heavyEddie Posted August 14, 2007 Share Posted August 14, 2007 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); } Quote Link to comment https://forums.phpfreaks.com/topic/64868-solved-stream_get_line-works-fgets-doesnt/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64868-solved-stream_get_line-works-fgets-doesnt/#findComment-323665 Share on other sites More sharing options...
heavyEddie Posted August 14, 2007 Author Share Posted August 14, 2007 Don't I feel silly... Thanks, the extra argument was the issue. I am parsing each line of the file, which is why I'm not using file_get_contents(). Thanks for the help and advise! Quote Link to comment https://forums.phpfreaks.com/topic/64868-solved-stream_get_line-works-fgets-doesnt/#findComment-323705 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.