0

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

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by HITMANOF44th
0

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.

0

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");
}

Edited by HITMANOF44th: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.