read the PHP documentation, he posted links on the functions.
mkdir() makes a new directory: http://php.net/mkdir
fopen() starts a new file stream: http://php.net/fopen
once you have started a new stream you can write to it using fwrite(): http://php.net/fwrite
and save it using fclose(): http://php.net/fclose
I'll write you a small script:
<?php
$dir = 'myDir';
$file = 'myFile.php';
// check the directory to see if it already exists
if( is_dir($dir) === false )
{
// if it doesn't make a new directory
mkdir($dir);
}
// start a new stream
$f = fopen($file, 'w'); // 'w' for write
// write the php to the stream
fwrite( $f, '<?php echo "Hello world!"; ?>' );
// close the stream
fclose($f);
// include our new php script to see if it's working:
include $myDir . '/' . $myFile; // Hello world!
?>