使用正则表达式使链接可单击

1 php regex

是否有一个正则表达式可以找到一个字符串,其中包含一个以http://或www开头并用它包装的单词<a>$1</a>

谷歌搜索,但我似乎无法找到一个终极的.

另一个问题,你可以以某种方式让它忽略它,如果它在<img>标签内?

谢谢你!

Dev*_*tas 8

    $text = trim($text);
    while ($text != stripslashes($text)) { $text = stripslashes($text); }    
    $text = strip_tags($text,"<b><i><u>");
    $text = preg_replace("/(?<!http:\/\/)www\./","http://www.",$text);
    $text = preg_replace( "/((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>",$text);
Run Code Online (Sandbox Code Playgroud)