sheraz Posted September 7, 2009 Share Posted September 7, 2009 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. 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 Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/ Share on other sites More sharing options...
ram4nd Posted September 7, 2009 Share Posted September 7, 2009 http://us.php.net/manual/en/function.fpassthru.php read how the command works Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-913964 Share on other sites More sharing options...
RussellReal Posted September 7, 2009 Share Posted September 7, 2009 I'm GUESSING fpassthru returns the strlen of the string but outputs the contents inside the function not returns the value of the string. Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-913971 Share on other sites More sharing options...
sheraz Posted September 7, 2009 Author Share Posted September 7, 2009 http://us.php.net/manual/en/function.fpassthru.php read how the command works sir if it only return the total number of readed characters then i don't understand that why it is returning the file contents. Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-913992 Share on other sites More sharing options...
bundyxc Posted September 7, 2009 Share Posted September 7, 2009 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.'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-914018 Share on other sites More sharing options...
sheraz Posted September 7, 2009 Author Share Posted September 7, 2009 ok Thanks sir, i m very thankful to u. Quote Link to comment https://forums.phpfreaks.com/topic/173380-fpassthru/#findComment-914075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.