Welcome to WebmasterWorld Guest from 3.228.24.192

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Displaying A Files Contents...But Limited?

     
5:56 pm on Sep 22, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 11, 2004
posts:71
votes: 0


i have this....

<?php
$file = "news.txt";
if (!$file_handle = fopen($file,"r")) { echo "Cannot open file."; }
if (!$file_contents = fread($file_handle, filesize($file))) { echo "Cannot retrieve file contents."; }
else {
$filedone = ftruncate($file_contents,50);
echo "$filedone"; }
fclose($file_handle);
?>

but what i want to do is only display about 60 characters .... i have read that i need to use the ftranuce function but have had no luck implementing it... any ideas

6:54 pm on Sept 22, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Oct 20, 2003
posts:336
votes: 0


im not sure if it possible to limit to a certain number of characters. what you might want to try and work around this. what exactly are you doing? do you really need to limit it to 60 characters?
8:06 pm on Sept 22, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


ftruncate() [php.net] returns a boolean value (true/false). If it is a text file you are reading, the fread() [php.net] function can be passed the second argument of 60 and you'll get your 60 characters as desired. This is, of course, speculating that you really don't need to read the entire file into memory for anything else.
8:13 pm on Sept 22, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Oct 20, 2003
posts:336
votes: 0


sorry abt the wrong info there, too early assumption abt things.