fgets

(FW >= 1.0)

fgets - get a string from a resource

Description

string fgets(int handle, int size)
This will return a blank string if no data can be read.  This function works with different resource types.  For sockets and streams, this will block until a line feed/carriage return is reached.  For files, this will read till the end of the line or the end of the file.  If size is specified, the function will return the number of characters specified if the string is longer.

Parameters

handle

handle of a previously opened resource

size

option limit to the number of bytes returned

Return Value

string containing the line of characters (without the carriage return)

Examples

<pre><?
/**
* This example will open a TCP connection to google.com and get the header for a search for 'test'
**/
$f=fsockopen("www.google.com",80,10);
if ($f) {

$out = "GET /search?q=test HTTP/1.0\r\n";
$out = $out."Host: www.google.com\r\n";
$out = $out."Connection: Close\r\n\r\n";
fwrite($f, $out);
print($out);
// get header
$done=0;
while (!$done) {
$str=fgets($f);
print($str+"\r\n");
if (strlen($str)==0) $done=1;
}

fclose($f);

}
?>
</pre>