约翰格鲁伯刚刚发布了一个有趣的正则表达式例子来捕捉网址: Daring Fireball regex to get URLs
要切入正题,在(自由的,长),他选择模式是:
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
这假定捕获以下所有:
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:[email protected]:8080
http://[email protected]
http://[email protected]:8080
http://userid:[email protected]
http://example.com:8080 x-yojimbo-item://6303E4C1-xxxx-45A6-AB9D-3A908F59AE0E
message://%[email protected]%3e
http://➡.ws/䨹
www.➡.ws/䨹
<tag>http://example.com</tag>
Just a www.example.com link.
所以,你会使用模式的东西,如preg_filter,然后迭代OV呃以某种方式返回返回的数组。我猜。我讨厌正则表达式。
http://stackoverflow.com/questions/1798912/replace-any-urls-within-a-string-of-text-to-clickable-links-with-php – Sampson 2009-12-08 04:41:58
http://stackoverflow.com/questions/1038284/PHP的解析链接的电子邮件中 – Sampson 2009-12-08 04:42:34