我现在正在使用 PHP 和 WordPress,我基本上需要运行下面的代码来用if EXIST in 中$current_path
的文本替换文本$new_path
$current_path
$content
我希望能够迭代一个数组,而不是像这样一遍又一遍地运行它,或者任何更好的方法会很好?
$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);