How to escape $ in php using preg_replace ?

Posted by sakura on Stack Overflow See other posts from Stack Overflow or by sakura
Published on 2009-04-20T10:35:13Z Indexed on 2010/05/22 3:10 UTC
Read the original article Hit count: 152

Filed under:
|

Hi, I am using preg_replace to escape special characters...

         $tmpStr=preg_replace("/\?/", "\?", $tmpStr);
         $tmpStr=preg_replace("/\#/", "\#", $tmpStr);
         $tmpStr=preg_replace("/\^/", "\^", $tmpStr);
         $tmpStr=preg_replace("/\&/", "\&", $tmpStr);
         $tmpStr=preg_replace("/\*/", "\*", $tmpStr);
         $tmpStr=preg_replace("/\(/", "\(", $tmpStr);
         $tmpStr=preg_replace("/\)/", "\)", $tmpStr);
         $tmpStr=preg_replace("/\//", "\/", $tmpStr);

but i am not able to escape $ using the same function

$tmpStr=preg_replace("/\$/", "\$", $tmpStr);

and also when i use the above statement all the spaces get replaced by $ and $ is not getting escaped....someone please help me with this....

© Stack Overflow or respective owner

Related posts about php

Related posts about preg-replace