How to use str_replace in php to search and replace multiple words?
PHP中文网
PHP中文网 2017-05-16 13:09:26
0
1
609

For example, string:

I|You|He

How to replace with

Pig|Cat|Dog

$str = "I|You|He";
$replace_str = str_replace(array("I","You","He"),array("Pig","Cat","Dog"),$str);
print($replace_str);

php output:
    "I|you|dog"
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
習慣沉默

How did the poster test it and under what environment? The code provided by the poster is the correct answer

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template