【发布时间】:2014-07-09 11:29:59
【问题描述】:
当我尝试使用 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;
?>
以上结果
我的汤里有动物饼干 - 加上一些测试文本
感谢您的帮助。
谢谢大卫
【问题讨论】:
-
激活错误报告!它会告诉你你的变量名打错了。
-
TYPO - $seachfor 和 $searchfor
-
通常最好复制/粘贴变量以避免拼写错误。
-
@Koninos 或者使用像样的 IDE...
标签: php user-defined-functions str-replace