Forum Moderators: coopster

Message Too Old, No Replies

replace $ from php variable

         

hibuddy

5:28 am on Oct 14, 2005 (gmt 0)

10+ Year Member



Hi

In my PHP script I have a "$" stored in one of my variable like $var1 is AAA$BBBCC.

while I am trying to print I am not getting the part after $ symbol ( I am only getting AAA). I am trying to replace my variable's value to AAA\$BBBCC by($var1=preg_replace('$', '\$', $var1);)

It is not working for me.I would appreciate If you could help on that.

Thanks...

jatar_k

4:49 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you sure the value is getting stored properly in the variable?

Robber

5:02 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



I think if you are using preg_replace you'll need something along the lines of:

$var1=preg_replace('/\$/', '\\\$', $var1);

The forward slashes act as the regex delimiters and the back slashes are escaping special characters. In the firt argument the $ needs esaping as it usually means anchor the earch pattern to the start of the string. The \\\ is required to escape the normal meaning of the backslash.

Hope that helps