dua55014 2014-07-09 11:29
浏览 54
已采纳

PHP str_replace()在用户定义的函数中不起作用

When I try to make a user defined function using str_replace it has no effect. Components of the same code work perfectly when not in a user defined function. The following shows a simple representation of my problem.

<?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;
?>

The above results in

Animal crackers in my soup - plus some test text

Any help gratefully received.

Thanks David

  • 写回答

1条回答 默认 最新

  • duanhao7786 2014-07-09 11:33
    关注

    Spell $seachfor correctly and it will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?