Jump to content

Recommended Posts

Hi there. Running examples from a webbots book. Here's the code:

 

<?

$target = "http://www.schrenk.com/nostarch/webbots/hello_world.html";

$file_handle = fopen($target, "r");

 

#fetch the file

while (!feof(file_handle))

echo fgets($file_handle, 4096);

fclose($file_handle);

 

?>

 

I ran it from terminal on OS X 10.5 (FWIW) and it spat back infinite lines of:

 

Warning: feof(): supplied argument is not a valid stream resource

 

Instead of the expected line-by-line response from the targeted web server.

 

It DOES show the source HTML after each error message, but when the source is done, the errors continue to infinity and I have to close Terminal.

 

I'm a PHP newbie, so go ahead and talk down to me  ;)

 

Thanks for explaining what's happening,

 

Alex

Link to comment
https://forums.phpfreaks.com/topic/141889-solved-feof-error/
Share on other sites

hrmm. at -least a semi colon. (isn't it always a semi-colon?) but that still dumped out the errors.

 

I don't know much about the functions (it's a hello world example, after all)

 

file_handle looks like a variable, so I tried it with a $ in front: 

 

while (!feof($file_handle));

 

but that didn't reply with -anything-

 

still stumped!

Link to comment
https://forums.phpfreaks.com/topic/141889-solved-feof-error/#findComment-742941
Share on other sites

Your error was that you were missing the $.

 

If you aren't getting anything, that is a separate problem with your code, and you should start a new thread, as this error has been solved.

 

Also, you should use <?php instead of <?. The short tag that you are using is sloppy programming as it may stop working suddenly if your host changes their server settings. Or if you move it to a new server, it may not work if they have short tags turned off.

Link to comment
https://forums.phpfreaks.com/topic/141889-solved-feof-error/#findComment-742943
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.