V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
world
V2EX  ›  问与答

求以正则表达式

  •  1
     
  •   world · Apr 14, 2015 · 2792 views
    This topic created in 4045 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   ·   4058 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 04:19 · PVG 12:19 · LAX 21:19 · JFK 00:19
    ♥ Do have faith in what you're doing.