world
V2EX  ›  问与答

求以正则表达式

  •  1
     
  •   world · Apr 14, 2015 · 2827 views
    This topic created in 4056 days ago, the information mentioned may be changed or developed.

    先贴上源码
    add_filter('the_content','baezone_the_go_url',999);
    function baezone_the_go_url($content){
    preg_match_all('/href="(.*?)"/',$content,$matches);
    if($matches){
    foreach($matches[1] as $val){
    if( strpos($val,home_url())===false ) $content=str_replace("href=\"$val\"", "href=\"" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val). "\"",$content);
    }
    }
    return $content;
    }

    现在的匹配规则是匹配文章内所有的链接,但是考虑到需求,我想在匹配文章内链接的基础上加一个例外,不匹配图片上的链接。
    正则表达不会写,求各位大大指点一下

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2784 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:58 · PVG 20:58 · LAX 05:58 · JFK 08:58
    ♥ Do have faith in what you're doing.