why this code does not work ?
$mx['foo'] = "vvv";
$string = "foo is foobar, baz is widgets";
echo preg_replace("/(foo)/ei", "$mx[('\\1')]", $string );
the output must like this
vvv is vvvbar, baz is widgets
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because you are using double quotes in
preg_replace, PHP tries to use your$mxvalue directly, which produces then error…Simply escape the
$mx, and then it will work:Or you can do the same by using single quotes: