![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
Reading contents of text file then printing out, not working.
I have the following code:
<?php
$fp = file('abc.txt');
echo "$fp";
?>it is supposed to get all the text from abc.txt and print it out, however its only printing out one word: 'array', and 'array' isn't even in the text file. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
Php.net is your friend. Or google. Or any search engine. It actually takes LESS time to google this then to come and post it.
http://www.php.net/file file() returns an array with each line as a member. You need to use a for each loop to get each line and print it out.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi freelance scripts - http://ryanguthrie.com/index.html |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
[php]<?php readfile("abc.txt"); ?>[/php]
|
|
|
|
|
|
#4 | |
|
Newbie
|
Quote:
<?php
$fp = file('abc.txt');
echo implode('', $fp);
?>
__________________
Aryo Sanjaya Sangkan paraning dumadi Manunggaling kawulo gusti |
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
[PHP]
$filearray = file($filename); if($filename) { while(list($var, $val) = each($filearray)) { ++$var; $val = trim($val); print $val; } } else { print "Couldn't open $filename"; } [/PHP] |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() |
Or my preference:
<?php echo file_get_contents($filename); ?> |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|