简体   繁体   English

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

[英]PHP str_replace not working in my case

I am trying to do string replace on an array. 我正在尝试在数组上进行字符串替换。

I have.. 我有..

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

The $test->html returns $test->html返回

and I want to replace all texts to testssssss.. 我想将所有文本替换为testsssss ..

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! 谢谢您的帮助!

您需要在某个地方分配新值,str_replace不会自动覆盖主题:

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

该函数返回字符串,因此您需要启动它$ variable = str_replace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM