0

How can I replace multiple strings with str_replace?

$oldurl = JFactory::getURI();
$newurl = str_replace('example1', 'replacedwiththis', $oldurl);

but I need that this code works also if the URL contains example2. So I need a code that changes both example1 and example2 with replacedwiththis.

1 Answer 1

2

With str_replace() you can define an array of 'needles' to find (http://php.net/manual/en/function.str-replace.php).

So you can do ...

$newurl = str_replace(['example1','example2'], 'replacedwiththis', $oldurl);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.