简体   繁体   中英

Replacing more than one string with str_replace?

As mentioned in the title im trying to replace more than one string and im worndering if its possible with str_replace(); Or is there a easier way?

Example:

str_replace('hello','#$@&%*!',$text);

I'm replacing "hello" with "#$@&% !" but i also want "world" to get replaced with "#$@&% !" .

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) Parameter "search": The value being searched for, otherwise known as the needle. An array may be used to designate multiple needles.

http://www.php.net/manual/en/function.str-replace.php

Try this

$text = 'hello this is world';
echo str_replace(array('hello','world'),'#$@&%*!',$text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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