Hi,

The following code is taken from php.net, and demonstrates how to use a soccet and print the returned data.

$fp = fsockopen ("www.php.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}

in my script, the returned data has multiple lines and I only want to display the last line of the returned data (not all as above)and load the value into a string.

Please can anyone tell me how?

Thanks

Stephen Fletcher

    Try:

    if (!$fp) {
    echo "$errstr ($errno)<br>\n";
    } else {
    fputs ($fp, "GET / HTTP/1.0\r\n\r\n");
    while (!feof($fp)) {
    $sTemp = fgets($fp, 4096);
    }
    // just echo last line...
    // note more realistic max line length
    // of 4096
    echo($sTemp);
    fclose ($fp);
    }

    Dave

    ===========================================
    http://badblue.com/helpphp.htm
    Free small footprint web server for Windows

    P2P file-sharing, PHP, wireless apps & more

      Write a Reply...