drmcm84800
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

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



Key 2

<div>
    other html...
</div>


Key 3

<div>
    other html...
</div>

Key 4

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

more...

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

    点赞 评论 复制链接分享

相关推荐