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

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
cemlouis
Forum Newbie
Posts: 4
Joined: Sun Jul 21, 2002 7:48 am

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

Post 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???
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can also have each line read into an array:
http://www.php.net/manual/en/function.file.php

Mac
rev
Forum Commoner
Posts: 52
Joined: Wed Oct 02, 2002 3:58 pm
Location: Atlanta, GA

Post by rev »

Code: Select all

<?php
$fileArray = file("/path/to/file.txt");
foreach($fileArray as $eachLine) {
	echo $eachLine."<br>\n";
}
?>
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I think he can work that out by himself(or herself)...
rev
Forum Commoner
Posts: 52
Joined: Wed Oct 02, 2002 3:58 pm
Location: Atlanta, GA

Post by rev »

...and I have no doubt that they can now.
Post Reply