preg_replace with backslash, dollar sign and double quote

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lyoute
Forum Newbie
Posts: 2
Joined: Sun Nov 03, 2002 9:35 pm

preg_replace with backslash, dollar sign and double quote

Post by lyoute »

$str = '\\\\$hello \\\"world';
$str = preg_replace("/\\\*\$/","\$",$str);
$str = preg_replace("/\\\*\"/","\"",$str);
print $str;

output :
$hello "world$

but what i expect is \$hello \"world

any problem with my regular expression?
lyoute
Forum Newbie
Posts: 2
Joined: Sun Nov 03, 2002 9:35 pm

Post by lyoute »

oh i got it...

$str = preg_replace("/\\\*\\$/","\\\\$",$str);
$str = preg_replace("/\\\*\"/","\\\"",$str);

\\\\$ = "\\"."\\$"
\\\" = "\\"."\""
arghhh....so tricky... :(
Post Reply