PHP 可以轻松处理这个问题。
<?php echo str_replace('dog','cat',$status); ?>
第一个词是要搜索的项目,第二个词是替换它的内容,第三个项目是要在其中搜索的内容。
编辑
根据要求,提供了一个如何使其可用于许多项目且不区分大小写的示例。首先,制作一个PHP函数:
function replaceWords($existing,$new,$content){
str_ireplace($existing,$new,$content);
}
然后为所有要查找的单词和要替换的所有单词创建数组(以相同的顺序):
$existing_array = array('dog','elephant','bird');
$new_array = array('cat','eagle','your mom');
// dog replaced with cat, elephant replaced with eagle, bird replaced with your mom
然后使用for循环调用函数:
for($i = 0; $i < 150; $i++){
function replaceWords($existing_array[$i],$new_array[$i],$status);
}
我做了 150,因为你提到了这个数字,但确切的字数应该在那里。那应该这样做。
更多信息可以在这里找到。
第二次编辑
一个更加自动化的for循环:
$cnt = count($existing_array); // you can use either array, since they're the same length
for($i = 0; $i < $cnt; $i++){
function replaceWords($existing_array[$i],$new_array[$i],$status);
}
这样,您只需将项目添加到数组中,新的字数将是for循环的新长度。手动代码越少越好。