2012-10-18 16:52 阅读 45

PHP str_replace在我的情况下不起作用

I am trying to do string replace on an array.

I have..

str_replace('texts', 'testssssss', $test->html);

The $test->html returns

and I want to replace all texts to testssssss..

key 1

   <a href='texts.company.name.html'>test</a>

Key 2

    other html...

Key 3

    other html...

Key 4

   <a href='texts.department.name.html'>department</a>


Thanks for the help!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douman6245 douman6245 2012-10-18 16:54

    You need to assign the new value somewhere, str_replace does not automatically overwrite the subject:

    $test->html = str_replace('texts', 'testssssss', $test->html);
    点赞 评论 复制链接分享
  • dongyouzhi7218 dongyouzhi7218 2012-10-18 16:56

    The function returns the string so you need to start it $variable =str_replace

    点赞 评论 复制链接分享