how do i make a txt 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
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

how do i make a txt file?!

Post 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?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Yes. What part is giving you problems?
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Post by Black Majin »

lol i'm sorta a n00b at this so i dont even know where to start :oops:
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Post 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
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Post by Black Majin »

Didnt find anything, if its not too much to ask can someone plz make me a small script for it...
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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);
}
Black Majin
Forum Newbie
Posts: 22
Joined: Wed Jul 16, 2003 12:51 pm
Location: Garland, Texas

Post by Black Majin »

Ok thnx man :)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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. ;)
Post Reply