查找字符串中的所有链接,并使用PHP将它们转换为锚定标记
应该成为查找字符串中的所有链接,并使用PHP将它们转换为锚定标记,php,regex,Php,Regex,应该成为 http://stackoverflow.com 编辑:如果原始字符串中的锚定标记保持不变,那就太好了。John Gruber刚刚发布了一个有趣的正则表达式示例来捕获URL: 为了切入正题,他选择了(自由的、长期的)模式: <a href="http://stackoverflow.com">http://stackoverflow.com</a> \b(([\w-]+:/?(www[.])[^\s()]+(?:\([\w\d]+\)|([^[:pun
http://stackoverflow.com
编辑:如果原始字符串中的锚定标记保持不变,那就太好了。John Gruber刚刚发布了一个有趣的正则表达式示例来捕获URL: 为了切入正题,他选择了(自由的、长期的)模式:
<a href="http://stackoverflow.com">http://stackoverflow.com</a>
\b(([\w-]+:/?(www[.])[^\s()]+(?:\([\w\d]+\)|([^[:punct:][\s]./))
这假定要捕获以下所有内容:
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
http://foo.com/blah_blah
http://foo.com/blah_blah/
(差不多http://foo.com/blah_blah)
http://foo.com/blah_blah_(维基百科)
(差不多http://foo.com/blah_blah_(维基百科)
http://foo.com/blah_blah.
http://foo.com/blah_blah/.
http://foo.com/blah_blah,
http://www.example.com/wpstyle/?p=364.
http://✪df.ws/123
rdar://1234
rdar:/1234
http://userid:password@example.com:8080
http://userid@example.com
http://userid@example.com:8080
http://userid:password@example.com
http://example.com:8080 x-yojimbo-item://6303E4C1-xxxx-45A6-AB9D-3A908F59AE0E
信息://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e
http://➡.ws/䨹
www。➡.ws/䨹
http://example.com
只是一个www.example.com链接。
因此,您将使用类似的模式,然后以某种方式迭代返回的匹配数组。我想是吧。我讨厌正则表达式
http://foo.com/blah_blah
http://foo.com/blah_blah/
(Something like http://foo.com/blah_blah)
http://foo.com/blah_blah_(wikipedia)
(Something like http://foo.com/blah_blah_(wikipedia))
http://foo.com/blah_blah.
http://foo.com/blah_blah/.
<http://foo.com/blah_blah>
<http://foo.com/blah_blah/>
http://foo.com/blah_blah,
http://www.example.com/wpstyle/?p=364.
http://✪df.ws/123
rdar://1234
rdar:/1234
http://userid:password@example.com:8080
http://userid@example.com
http://userid@example.com:8080
http://userid:password@example.com
http://example.com:8080 x-yojimbo-item://6303E4C1-xxxx-45A6-AB9D-3A908F59AE0E
message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e
http://➡.ws/䨹
www.➡.ws/䨹
<tag>http://example.com</tag>
Just a www.example.com link.