Jump to content

fpassthru()


sheraz

Recommended Posts

hi i m working on fie handling. i have used fpassthru() to read the data froma file . it outputs the contents of file but at the end it also prints total number of characters. please tell me what the problem is. :wtf:

 

here is the code.

 

if(! $fp=fopen("abc.txt", "r"))

 

die("could not find the required file");

else

{

echo fpassthru($fp);

}

?>

 

its output is

 

welcome to php programming.we are working on the php file handling. 68

 

Link to comment
https://forums.phpfreaks.com/topic/173380-fpassthru/
Share on other sites

Consider this:

 

function helloWorld() {
    print('Hello World!');
    return 'PHP is awesome!';
}

$return = helloworld(); //This will execute the helloWorld function, print "Hello World!", and set $return.
print('<br />');        //Line break, just for the sake of formatting.
print($return);         //This will print the return of the helloWorld function, and echo 'PHP is awesome!';

 

This code would return:

 

Hello World!

PHP is awesome!

 

What a function does, and what a function returns are two completely seperate things.

 

Try this code instead:

 

<?php
if (!fopen('abc.txt', 'r')) {
    die('Could not find the required file.');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-914018
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.