Jump to content

[SOLVED] stream_get_line works... fgets doesn't


heavyEddie

Recommended Posts

I'm trying to use the code below to parse some information in a text file that is generated on a remote server.  If I use stream_get_line it works nicely, but fgets simply gets stuck in an endless loop.  Any ideas?

 

I wish to use fgets since it appears that stream_get_line isn't available on many hosts.

 

$file = "http://www.site.com/bla.pl?id=1";
$handle = fopen($file, "r");

// Read each line of the file and check to see if this person is still logged in or not.
if ($handle) {
    while (!feof($handle)) {
    	  //$buffer = stream_get_line($handle, 1000, "\n");
    	  $buffer = fgets($handle, 4096, "\n");
    	  //bla bla bla bla bla
     }
    fclose($handle);
}

Link to comment
Share on other sites

Why do you have three arguments in fgets()? It should only accept two. If you just put the one argument ($handle) it will read to the end of the line, unless, for some reason, you only want the first 4096 bytes of a line.

 

However, if you are just putting the contents of the file into a buffer string, why don't you just use file_get_contents()? It is the most efficient functions this sort of thing.

Link to comment
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.