can you write a tutorial to show how to create a file using php

i want to be able to create a file and put some code in it

can that be done? i know creating a file you have to use the fopen function but thats all i have learn so far so i want to know how i would go about making a file in using php scripts, can you send me the step by step instructions.

thanks