PDA

View Full Version : Real Quick PHP Question


Semperfidelis
Mon 28th Jul '03, 11:58am
How via a php file do you call the contents of a txt file ?

ie
Say you had http://www.mydomain.com/test.php
And you wanted the contents of content.txt to be displayed.


Thanks

Chen
Mon 28th Jul '03, 12:15pm
readfile('./content.txt'); is the most simple way. If you want to alter the data of the file, you can use file() to get the contents in the form of an array, or use file_get_contents() which is only available in later versions of PHP.

Semperfidelis
Mon 28th Jul '03, 12:25pm
Cheers Chen
:)

Daijoubu
Tue 29th Jul '03, 10:43am
$file = fopen("content.txt", r);
fpassthru($file);
or
$file = fopen("content.txt", r);
fread($file, filesize("content.txt"));
or
readfile(content.txt);
or
file_get_contents(content.txt); (PHP4.3.0+)
or
include(content.txt);

there's another way too with file and explode :D

Chen
Tue 29th Jul '03, 10:48am
$file = fopen("content.txt", r);
fpassthru($file);
or
$file = fopen("content.txt", r);
fread($file, filesize("content.txt"));
or
readfile(content.txt);
or
file_get_contents(content.txt); (PHP4.3.0+)
or
include(content.txt);

there's another way too with file and explode :D
Surely you mean file() and implode(). :)

Daijoubu
Tue 29th Jul '03, 9:05pm
Indeed ;)
I found fpassthru be the fastest, but i could be wrong :)