|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-07-18 04:18 UTC] christoffer at leitet dot no
I've made a function that asks whoisservers for information:
<?
$WhoIsServer="whois.nic.as";
$fp = fsockopen ("$WhoIsServer", 43, $errnr, $errstr);
set_socket_blocking($fp,0);
fputs($fp, "$domain\n"); // Open a connect
while (!feof($fp)) {
$result = fgets($fp, 2048);
$test = ereg_replace(10, " ", $result); // I've tried both ereg_replace(), stripslashes(), stripcslashes() and str_replace() (only ereg_replace and str_replace has worked the way I want)
print substr("$result",0,4);
if (substr("$test" ,12,8) == "Server") { //Hvis ledig
echo "$MsgFree";
}
else if (substr("$test" ,0, 6) == "Rights") { // Hvis opptatt
printf ("$MsgTaken");
}
}
fclose($fp); // Close
}
?>
When I output the str_replaced string with print, printf and echo, it is all on one line without newlines (I've tried both with \n and ASCII character 10 to represent the newline). But when I use substr($test, 0,12) fx. then it output the twelveth first characters in every line in the original string ($result). When I use substr($test, 2,4), it outputs the 2nd to 4th character in every line in the original $result instead of printing the 2nd to 4th character in the new string that shouldn't contain any newlines.
I use a standard php.ini, and has no unique setup. I've tried this out on both 3.0.16 and 4.0.0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
fclose() should be outside the while loop. the first parameter of ereg_replace is a string - the pattern to search for. fgets is returning one line each time so of course your print substr() is being called for each time around the while loop You want something like this: ... fputs($fp, "$domain\n"); $data = ""; while (!feof($fp)) { $data .= fgets($fp, 2048); } $test = str_replace("\n", " ", $data);