...

View Full Version : Creating a .txt file with PHP



[_bushido_]
02-26-2006, 02:00 AM
Creating a ".txt" file (or any text file for that matter) can be done simply with PHP.

So lets start shall we?
What will we be using?
fopen(); (http://us2.php.net/manual/en/function.fopen.php)
fwrite(); (http://us2.php.net/manual/en/function.fwrite.php)
fclose(); (http://us2.php.net/manual/en/function.fclose.php)
strlen(); (http://us2.php.net/manual/en/function.strlen.php)



<?php
$filename = "test01.txt"; //the name of our file.
$content = "This is our test file"; //what we will be writing to our file.
$strlength = strlen($content); //gets the length of our $content string.
$create = fopen($filename, "w"); //uses fopen to create our file.
$write = fwrite($create, $content, $strlength); //writes our string to our file.
$close = fclose($create); //closes our file
echo("File Created, Click <a href='$filename'> Here </a> to view it.");
?>

This is just very basic, i hope it can help someone.

Pennimus
02-26-2006, 02:08 AM
Is it me or did somebody just open a can of tasty luncheon meat in here?

[_bushido_]
02-26-2006, 02:09 AM
Is it me or did somebody just open a can of tasty luncheon meat in here?

huh? lol

degsy
02-27-2006, 03:56 PM
This is more of a forum for posting questions and problems.

There is another forum for code snippets.

managedinternet
01-29-2007, 01:55 AM
thanks !
thats nearly exactly what i was going to come here and ask

cheers !

CFMaBiSmAd
01-29-2007, 04:39 AM
The fwrite() example code in the php manual http://us2.php.net/manual/en/function.fwrite.php is several times better than the posted code as the code in the manual includes error checking and error reporting, which is often neglected in sample code, tutorials, and by beginning programmers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum