how do i make a txt file?!
Moderator: General Moderators
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
how do i make a txt file?!
I need a php script that when executed, it will make a certain amount of diff .txt files. But they will be in numerical order starting from 00.txt to 50.txt is that possible?
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
http://www.php.net and looking up functions is a good place to start. as s searching this forum for books and seeing what's recommended
Specifically read about fopen() and fwrite to see how to make PHP create and write to a file.
You can use a loop to generate the 50 files from some simple logic to pad the leading zeroes, etc
Take it one step at a time. First try to write down, in english (or your native language) the steps that need to be done. Look at the list. See if you can break down some steps further. Pretend you are giving directions to a forgetful person and must use simple,short steps only. Now try to see how to convert each natural language step into PHP.
You can use a loop to generate the 50 files from some simple logic to pad the leading zeroes, etc
Take it one step at a time. First try to write down, in english (or your native language) the steps that need to be done. Look at the list. See if you can break down some steps further. Pretend you are giving directions to a forgetful person and must use simple,short steps only. Now try to see how to convert each natural language step into PHP.
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
This should get you started, but I haven't tested it so its probably buggy to some degree.
Code: Select all
$path = "Something you need to fill in, what directory should the files be written to, make sure you PHP has permission to write to this directory";
for ($i=0;$i<50;$i++)
{
if ($i<10) $filename="0".$i;
else $filename=$i;
$filename .= ".txt";
$filecontents = "I have no idea what you want to put here...."
$fp = fopen("$path/$filename","w"); // if in windows you have to chace the / to \\
fwrite($fp,$filecontents);
fclose($fp);
}-
Black Majin
- Forum Newbie
- Posts: 22
- Joined: Wed Jul 16, 2003 12:51 pm
- Location: Garland, Texas
Also check out snipplet sites like http://www.hotscripts.com/PHP and http://www.evilwalrus.com because someone may have posted the bit of code your looking for. 