0

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 "#$@&%!".

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked with $words = array('wordone','wordtwo'); $replace = str_replace($words,'#$@&%*!',$replace); return $replace;
0

Try this

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.