Forum Moderators: coopster

Message Too Old, No Replies

Displaying A Files Contents...But Limited?

         

quozt

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

10+ Year Member



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

kumarsena

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

10+ Year Member



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?

coopster

8:06 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



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.

kumarsena

8:13 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



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