Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 15th, 2006, 12:41 PM   #1
chillypacman
Newbie
 
Join Date: Mar 2006
Posts: 21
Rep Power: 0 chillypacman is on a distinguished road
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.
chillypacman is offline   Reply With Quote
Old Jun 15th, 2006, 12:47 PM   #2
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 224
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
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
Mocker is offline   Reply With Quote
Old Jun 15th, 2006, 2:02 PM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
[php]<?php readfile("abc.txt"); ?>[/php]
Arevos is offline   Reply With Quote
Old Jun 19th, 2006, 6:50 AM   #4
Aryo Sanjaya
Newbie
 
Aryo Sanjaya's Avatar
 
Join Date: Jun 2005
Location: Malang - Indonesia
Posts: 2
Rep Power: 0 Aryo Sanjaya is on a distinguished road
Send a message via Yahoo to Aryo Sanjaya
Quote:
Originally Posted by chillypacman
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.
<?php 
	  $fp = file('abc.txt'); 
	  echo implode('', $fp);
?>
__________________
Aryo Sanjaya

Sangkan paraning dumadi
Manunggaling kawulo gusti
Aryo Sanjaya is offline   Reply With Quote
Old Jun 19th, 2006, 7:10 AM   #5
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
[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]
Toro is offline   Reply With Quote
Old Jun 19th, 2006, 7:29 AM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,188
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Or my preference:
<?php echo file_get_contents($filename); ?>
Sane is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:40 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC