note 96074 added to function.feof

From: Date: Sun, 07 Feb 2010 05:01:54 +0000
Subject: note 96074 added to function.feof
Groups: php.notes 
Request: Send a blank email to php-notes+get-165721@lists.php.net to get a copy of this message
When using feof() on a TCP stream, i found the following to work (after many hours of frustration and anger): NOTE: I used ";" to denote the end of data transmission. This can be modified to whatever the server's end of file or in this case, end of output character is. <?php $cursor = ""; $inData = ""; while(strcmp($cursor, ";") != 0) { $cursor = fgetc($sock); $inData.= $cursor; } fclose($sock); echo($inData); ?> Since strcmp() returns 0 when the two strings are equal, it will return non zero as long as the cursor is not ";". Using the above method will add ";" to the string, but the fix for this is simple. <?php $cursor = ""; $inData = ""; $cursor = fgetc($sock); while(strcmp($cursor, ";") != 0) { $inData.= $cursor; } fclose($sock); echo($inData); ?> I hope this helps someone. ---- Server IP: 69.147.83.197 Probable Submitter: 24.64.243.148 ---- Manual Page -- http://www.php.net/manual/en/function.feof.php Edit -- https://master.php.net/note/edit/96074 Del: integrated -- https://master.php.net/note/delete/96074/integrated Del: useless -- https://master.php.net/note/delete/96074/useless Del: bad code -- https://master.php.net/note/delete/96074/bad+code Del: spam -- https://master.php.net/note/delete/96074/spam Del: non-english -- https://master.php.net/note/delete/96074/non-english Del: in docs -- https://master.php.net/note/delete/96074/in+docs Del: other reasons-- https://master.php.net/note/delete/96074 Reject -- https://master.php.net/note/reject/96074 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165721) next »