【发布时间】:2011-03-27 11:19:24
【问题描述】:
在我之前的question 的后续行动中,我想用以下格式的链接替换所有大写* 单词的每个实例:
dictionary.com/browse/<TERM>
我正在使用的preg_replace 电话是这样的:
$content = preg_replace('#[A-Z][A-Z]+#', '<a href="//dictionary.com/browse/$1">$1</a>', $content);
使用http://gskinner.com/RegExr,看来我的正则表达式是正确的,并且它应该在每次查找时都被替换。
我是否做错了什么,无论是在preg_replace 调用中,还是在将插件/过滤器注册到 Wordpress API 时?
调用的完整上下文:
function define_filter($content){
$content = preg_replace('#[A-Z][A-Z]+#', '<a href="//dictionary.com/browse/$1">$1</a>', $content);
}
add_filter('the_content', 'define_filter');
* 我使用[A-Z][A-Z]+ 语法来确保我不匹配像“I”和“A”这样的词
【问题讨论】:
标签: regex preg-replace wordpress