多个字符串替换PHP
问题描述:
PHP多个字符串替换PHP
$nn="ab bc cd cd ab";
$tttt=str_ireplace("cd","aaa",$nn);
$tt=str_ireplace("ab","aaa",$tttt);
但下面的编码工作不
$nn="ab bc cd cd ab";
$tttt=str_ireplace("cd" or "ab","aaa",$nn);
输出为 “AAA BC AAA AAA AAA”。请帮我simplyfying it.because有对于各种单词来说,更多的是替代。
答
您可以在第一个参数str_ireplace
中使用数组。
$nn="ab bc cd cd ab";
$replace_words = array("ab", "cd");
$tttt = str_ireplace($replace_words, "aaa", $nn);
与'foreach'一起使用数组。 – Script47
查找'preg_replace' –
在** PHP **中有关于函数** str_ireplace **的问题,那么为什么不简单地查看一下手册? - > http://php.net/manual/en/function.str-ireplace.php Rizier123