Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.