如何用str_replace替换多个字符串?

时间:2018-03-31 19:12:31

标签: php joomla str-replace

如何使用str_replace替换多个字符串?

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

但如果URL包含example2,我还需要此代码。 因此,我需要一个代码,example1example2同时更改replacedwiththis

1 个答案:

答案 0 :(得分:2)

使用str_replace(),您可以定义一个'needle'数组来查找(http://php.net/manual/en/function.str-replace.php)。

所以你可以......

$newurl = str_replace(['example1','example2'], 'replacedwiththis', $oldurl);