【发布时间】:2012-10-26 23:12:10
【问题描述】:
我做了一个函数,通过从数组中放入新单词来替换字符串中的单词。
这是我的代码
function myseo($t){
$a = array('me','lord');
$b = array('Mine','TheLord');
$theseotext = $t;
$theseotext = str_replace($a,$b, $theseotext);
return $theseotext;
}
echo myseo('This is me Mrlord');
输出是
这是我的王爷
应该是打印错了
这是我的先生
因为单词 (Mrlord) 不包含在数组中。
我希望我能很好地解释我的问题。任何帮助家伙
问候
【问题讨论】:
-
您要求替换
lord,它确实做到了 -
是的,但是 Mrlord 这个词是一个词,我不想改变......代码应该完全改变数组中的词
-
你会更好地使用正则表达式