PHP str_replace的用法
1 替换单个字符
<pre>
<?php
echo str_replace("world","Shanghai","Hello world!");
?>
</pre>
<pre>
//结果
Hello Shanghai!
</pre>
2 多个字符替换多个字符
<pre>
$result=str_replace(array(1,2,3), array(3,4,5), "good5 golly2 miss3 molly!");
echo $result;
</pre>
<pre>
//结果
good5 golly4 miss5 molly!
</pre>
3 如果碰到 要匹配的是相同的可以采取如下方法
<pre>
<?php
$pattern = array('/a/', '/a/', '/a/');
$replacement = array('x', 'y', 'z');
$subject = 'abcadeafg';
$res = preg_replace($pattern, $replacement, $subject , 1);
echo $res; // xbcydezfg
$pattern = array('/?/', '/?/', '/?/');
$replacement = array('x', 'y', 'z');
$subject = '?b?d?bfg';
$res = preg_replace($pattern, $replacement, $subject , 1);
echo $res; // xbydzbfg
?>
</pre>