Forum Moderators: coopster
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...
$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