I want to use the Preg_replace function to replace some characters in text with images.
When I write like this, I can do it normally.
$expression = "/@ bared teeth"; $reexpression = "bared teeth"; $text =preg_replace ($expression, ", $text);
But when I changed to the group after the replacement of the image URL has become www.test.com/static/expression/Array.gif.
$expression =array ("/@", "/@ despise/", "/@ Torture/"), $reexpression =array ("Bared teeth", "contempt", "torment"), $text =preg_replace ($expression, ", $text);
I just contacted PHP, I hope you can help to see
Reply to discussion (solution)
The value of the parameter is computed before the function is executed. So it is:
$replace = ";
$text = Preg_replace ($expression, $replace, $text);
Since $reexpression are arrays, the array and string are connected to Array.gif
Look at your needs and re-write:
$text = ' Don't->@, despise <-'; $reexpression =array ("Bared teeth", "despise", "torment");//Hope your program is best coded with UTF-8, the U modifier is to avoid accidental confusion in coding $find = ' #@ ('. Join (' | ', $reexpression). ') #u '; $replace = '; $text = Preg_replace ($find, $replace, $text);
In addition, your image in Chinese name, but also need to pay attention to the possible code generated under IE, resulting in a picture loading 404 error
Attached manual: Http://php.net/preg-replace
The value of the parameter is computed before the function is executed. So it is:
$replace = ";
$text = Preg_replace ($expression, $replace, $text);
Since $reexpression are arrays, so ...
Thank you so much, I'm finally ready.