字符串中的URL检测


URL detection in a string

可能重复:
Linkify Regex函数PHP Daring火球方法

我正在尝试从字符串中获取URL,我有这个

$link_count = count(explode('http',$post));
if($link_count > 0){
    preg_match_all("#https?://[^.'s]+'.[^'s]+#ix", $note, $matches);
    foreach(){} etc..
}

这里的问题是,我也想能够检测到这样的URL;http://www.link.com或www.link.com或link.comPs:我在这里搜索过类似的问题,但我还没有看到一个能解决所有这些类型的URL。

谢谢。

尝试

"/'b((http(s)?:'/'/)?(www'.[a-zA-Z0-9'/''':'?'%'.'&';=#'-'_'!'+'~',]*))/is

正如马里奥所说,没有协议前缀的链路在技术上不是链路。

试试这个正则表达式:

#(https?://)?([a-z0-9-]+'.)+[a-z0-9]+/?#i