代码之家  ›  专栏  ›  技术社区  ›  warren

preg\u replace不在Wordpress插件中替换

  •  1
  • warren  · 技术社区  · 15 年前

    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\ U更换


    呼叫的完整上下文:

    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]+

    1 回复  |  直到 8 年前
        1
  •  1
  •   warren    15 年前

    我认为函数需要返回替换的结果:

    return $content;
    

    '#\b[A-Z]+\b#'
    

    还有,你想 $0 (整场比赛),不是吗 $1 (第一个捕获组,您的正则表达式没有)