php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1673 ereg_replace doesn't handle \$var correctly
Submitted: 1999-07-06 17:03 UTC Modified: 1999-07-06 17:09 UTC
From: conley at enteka dot com Assigned:
Status: Closed Package: Other
PHP Version: 3.0.9 OS: Solaris 2.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: conley at enteka dot com
New email:
PHP Version: OS:

 

 [1999-07-06 17:03 UTC] conley at enteka dot com
In attempting to do lame macro functionality, I found that the \$login never matches strings like:

Your login is $login.

Here is the suspect code:

 while (! feof($form)) {
    // Grab a line at a time doing variable substitutions on $variable
    $line = fgets($form,1023);
    $new = ereg_replace("\$login", "newvalue", $line);
    if ($line != $new) {
      print "<PRE>line=[$line]</PRE>\n";
      print "<PRE>new=[$new]</PRE>\n";
    }
    print $line;
  }

If I change \$login to just login I find I get:

Your newvalue is $newvalue.

Which is correct, so I think the rest of the code is correct-- just the $ escaping is broken.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-06 17:09 UTC] andrey at cvs dot php dot net
You need to add an extra pair of backslashes in order for it to work,
since ereg_replace() internally sees your "\$" as just "$" and it matches
the end of the line instead of $.  So replace "\$" with "\\\$".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 03:01:28 2024 UTC