|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 10 10:00:02 2026 UTC |
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. :)