|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
28 + 42 = ?
Subscribe to this entry?

 [2000-07-18 04:18 UTC] christoffer at leitet dot no
I've made a function that asks whoisservers for information:

        $fp = fsockopen ("$WhoIsServer", 43, $errnr, $errstr);
        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


Add a Patch

Pull Requests

Add a Pull Request


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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 23:01:29 2024 UTC