V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
GASALA
V2EX  ›  问与答

求一段替换正文网址为链接的正则

  •  
  •   GASALA · 2013-10-23 10:06:29 +08:00 · 2075 次点击
    这是一个创建于 3832 天前的主题,其中的信息可能已经有所发展或是发生改变。
    用于wordpress的正文网址替换为链接,自己写了这段没问题,但是会影响到本来就是链接的网址,而且图片地址也被替换了。。。

    function autolink($content)
    {
    $content = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\1" target="_blank" rel="nofollow">\1</a>', $content);
    if( strpos($content, "http") === FALSE ){
    $content = eregi_replace('(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="http://\1" target="_blank" rel="nofollow">\1</a>', $content);
    }else{
    $content = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\1<a href="http://\2" target="_blank" rel="nofollow">\2</a>', $content);
    }
    return $content;
    }
    add_filter('the_content', 'autolink');
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2714 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:16 · PVG 23:16 · LAX 08:16 · JFK 11:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.