我用PHP和WordPress现在的工作,我需要基本运行下面的代码在$current_path
与文本$new_path
替换文本如果$current_path
存在$content
做多个搜索并替换PHP字符串?
我宁愿能够遍历数组而不是像这样一遍又一遍地运行,或者更好的方法会更好吗?
$content = 'www.domain.com/news-tag/newstaghere'
$current_path = 'test-tag';
$new_path = 'test/tag';
$content = str_replace($current_path, $new_path, $content);
$current_path = 'news-tag';
$new_path = 'news/tag';
$content = str_replace($current_path, $new_path, $content);
$current_path = 'ppc-tag';
$new_path = 'ppc/tag';
$content = str_replace($current_path, $new_path, $content);
检查:使用数组http://php.net/manual/en/function.str- replace.php – 2013-04-29 01:09:15