php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2104 ereg_replace doesn't work with $
Submitted: 1999-08-18 12:26 UTC Modified: 1999-11-11 20:20 UTC
From: craig at starpoint dot net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Unix/Solaris 2.5
Private report: No CVE-ID: None
 [1999-08-18 12:26 UTC] craig at starpoint dot net
My web form allows users to put in a dollar value which goes into a MySql database. We want to remove any $ sign in the submitted value before sending it the database. The command: ereg_replace("$","",$value) doesn't appear to have any affect. I change the command to: ereg_replace("#","b",$value) and submit #5555 I get: b5555 if I replace the command with ereg_replace("$","b",$value) and submit $5555 I get $5555b. it behaves like the $ anchor. I tried these also, they produce the same results:
ereg_replace("\$","b",$value)
ereg_replace(chr(36),"b",$value)

Of course I don't want the 'b' I want it to work like, ereg_replace("$","",$value)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-11 20:04 UTC] joey at cvs dot php dot net
This is bcz "$" is a meta character in regular expressions. It means "end of line".
So you are telling ereg_replace to replace "end of line" (usually the point between
the last char and the \n) with "". (This is what it already is!)

In the case of "\$", the php parser gobbles the \ before ereg can see it.

Quick answer:
Try
<?
$s = "$55";
$f = ereg_replace("\\$", "", $s);
print "$f\n";
?>

Real solution:
Read the manual really well, and I would suggest Jeff Friedl's book on regex
"Mastering Regular Expressions", from O'Reilly and Assoc.
:)
 [1999-11-11 20:20 UTC] joey at cvs dot php dot net
Opps, forgot to close it.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 11:00:01 2026 UTC