Page 1 of 1

how do i make a txt file?!

Posted: Wed Jul 30, 2003 10:52 pm
by Black Majin
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?

Posted: Wed Jul 30, 2003 11:00 pm
by nielsene
Yes. What part is giving you problems?

Posted: Wed Jul 30, 2003 11:05 pm
by Black Majin
lol i'm sorta a n00b at this so i dont even know where to start :oops:

Posted: Wed Jul 30, 2003 11:07 pm
by m3rajk
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

Posted: Wed Jul 30, 2003 11:23 pm
by nielsene
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.

Posted: Wed Jul 30, 2003 11:28 pm
by Black Majin
lol I was actually hoping someone could make me a small script for it but I guess not lol. I'll see if that site helps

Posted: Wed Jul 30, 2003 11:53 pm
by Black Majin
Didnt find anything, if its not too much to ask can someone plz make me a small script for it...

Posted: Thu Jul 31, 2003 12:06 am
by nielsene
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);
}

Posted: Thu Jul 31, 2003 1:34 am
by Black Majin
Ok thnx man :)

Posted: Thu Jul 31, 2003 2:27 am
by m3mn0n
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. ;)