Rumah >pembangunan bahagian belakang >tutorial php >求解关于preg_replace函数解决思路
求解关于preg_replace函数
我想使用preg_replace函数把text里面的部分字符替换成图片
当我这样写时可以正常执行
<br />$expression ="[email protected]/";<br />$reexpression ="呲牙";<br />$text=preg_replace($expression,'<img src="www.test.com/static/expression/'.$reexpression.'.gif" / alt="求解关于preg_replace函数解决思路" > ',$text);
<br />$expression =array("[email protected]/","[email protected]/","[email protected]/");<br />$reexpression =array("呲牙","鄙视","折磨");<br />$text=preg_replace($expression,'<img src="www.test.com/static/expression/'.$reexpression.'.gif" / alt="求解关于preg_replace函数解决思路" > ',$text);
$text = [email protected],->@鄙视<-';<br />$reexpression =array("呲牙","鄙视","折磨");<br />// 希望你的程序最好以UTF-8编码,u修饰符的作用就是避免编码出现意外的混乱<br />$find = '#@('. join('<br><font color='#FF8000'>------解决方案--------------------</font><br>', $reexpression) .')#u';<br />$replace = '<img src="www.test.com/static/expression/$1.gif" alt="$1"/>';<br />$text = preg_replace($find, $replace, $text);