php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5652
Submitted: 2000-07-18 04:18 UTC Modified: 2000-07-18 05:27 UTC
From: christoffer at leitet dot no Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0.0 OS: linux 2.2.16
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: christoffer at leitet dot no
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-18 05:27 UTC] david at cvs dot php dot net
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);

 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 06:05:54 2023 UTC