HI

I have a list of around 3000 letter combinations and I would like to turn each one into a .php file, but every file will have exactly the same content at the beginning. Does anyone know of a way to do this that doesn't involve me individually naming each file?

Thanks

I think that you are probably solving your problem the wrong way if this is the solution. Maybe you should post your requirement and get some feedback on other possible solutions.

Having said that, you can use a variable in the filename for the FOpen statement. It seems like a simple matter to read your file of letter combinations and successively open files with the required names and write whatever is required to those files.

ill take a stab at this but let me know know how it goes

//===================================================================================
// show current directory and may array empty
//===================================================================================
echo getcwd();
unset $files;
//===================================================================================
// set directory and get all the filenames in array dont use .. or .
//===================================================================================
$directory = "/somedirectory";// set your directory here
if ($handle = opendir($directory)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $files[] = $file;
        }
    }
    closedir($handle);
	}
//===================================================================================
// count the amount of files in arrays
//===================================================================================
$count = count(files);

//===================================================================================
// make a counter and use the rename command in php to rename the file with .php
//===================================================================================
 for ( $counter = 0 ; $counter <= $count; $counter += 1) {
rename($directory."/".$files[$counter]", "$directory."/".$files[$counter].".php");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.