Page 1 of 1

How can I capture a txt file's content to a variable

Posted: Sun Oct 06, 2002 6:32 am
by cemlouis
How can I capture a txt file's content to a variable??? For ex: i have a $message variable how can I send the inside of message.txt to this variable???

Posted: Sun Oct 06, 2002 7:20 am
by Coco
http://www.php.net/manual/en/function.fopen.php
and
http://www.php.net/manual/en/function.fread.php

never used them myself so i cant explain out of the manual

Posted: Sun Oct 06, 2002 7:37 am
by twigletmac
You can also have each line read into an array:
http://www.php.net/manual/en/function.file.php

Mac

Posted: Sun Oct 06, 2002 3:00 pm
by rev

Code: Select all

<?php
$fileArray = file("/path/to/file.txt");
foreach($fileArray as $eachLine) {
	echo $eachLine."<br>\n";
}
?>

Posted: Mon Oct 07, 2002 1:33 am
by Takuma
I think he can work that out by himself(or herself)...

Posted: Mon Oct 07, 2002 10:45 am
by rev
...and I have no doubt that they can now.