【发布时间】:2016-10-02 14:09:20
【问题描述】:
如何仅替换 <p>-Tag 中的单词,而不替换内容中的 <h3> 或 <p class="no-change">-Tag 中的单词?
我想改变这个:
<p>My Text and an Old Word and more </p>
在
<p>My Text and an New Word and more </p>
我试过了:
function changer($content){
$word = str_replace('Old Word', 'New Word', $content);
$content = preg_replace('/<h3>(.*?)<\/h3>/im', $word, $content);
return $content;
}
add_filter('the_content','changer');
但我得到了双重结果......
【问题讨论】:
-
$content 是帖子的内容。 ´
旧词等等
´
标签: php regex string preg-replace str-replace