Can php create a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Can php create a file

Post by Calimero »

Is there a way that php create a blank .txt file ex. test.php


Could this way this be done -
I make this file
Then in the script I declare its name as a variable
then I add to its name var $var and use ++$var with if or while loop to use it to create several names
then i use copy and rename each time with the name I found above.

Any suggestions and ideas are welcome


AND YEAH, can php Fopen() html source code to seek for something in it ?

Thanks Ahead!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

$howmanyfiles = 5;
for($x=0;$x<$howmanyfiles;$x++){
    $fname = 'test'.$x.'.php';
    touch($fname);
}
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Thanks, BUT

Post by Calimero »

I realy appreciate the effort, but, I am still a newbie, so little comment on what this does, and what to do with the code to pursue my goals,
THANKS :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

oookie..

Code: Select all

$howmanyfiles = 5; //this is how many files you want to create
for($x=0;$x<$howmanyfiles;$x++){ //this is just a loop that loops round 5 times in this case
    //the line below is the name of the file we want to create..
    //in this example it will create test0.php, test1.php, test2.php ..etc..up to test4.php
    $fname = 'test'.$x.'.php';
    //touch is the command that creates the empty file
    //see http://php.net/touch for more info
    touch($fname);
}
Post Reply