0
当我尝试使用str_replace创建用户定义函数时,它没有任何作用。当不在用户定义的函数中时,相同代码的组件完美工作。以下显示了我的问题的简单表示。PHP str_replace()在用户定义函数中不起作用
<?php
function replacelist($thetext) {
$seachfor = array("crackers","soup");
$replacewith = array("shapes","stew");
$newtext = str_replace($searchfor, $replacewith, $thetext);
return $newtext." - plus some test text";
}
?>
<?php
$mytext="Animal crackers in my soup";
$newphrase = replacelist($mytext);
echo $newphrase;
?>
在
动物饼干上述结果在我的汤 - 再加上一些测试文本
任何帮助感激地接受。
感谢大卫
激活错误报告!它会告诉你,你已经打错了你的变量名。 – deceze
TYPO - $ seachfor和$ searchfor – tiriana
通常复制/粘贴变量以避免拼写错误是一个好主意。 – Konst