約翰格魯伯剛剛發佈了一個有趣的正則表達式例子來捕捉網址: 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