http://stackoverflow.com
should become
<a href="http://stackoverflow.com">http://stackoverflow.com</a>
EDIT: It would be great if anchor tags from the original string stayed intact.
http://stackoverflow.com
should become
<a href="http://stackoverflow.com">http://stackoverflow.com</a>
EDIT: It would be great if anchor tags from the original string stayed intact.
John Gruber just posted an interesting regex example to capture URLs: Daring Fireball regex to get URLs
To cut to the chase, the (liberal, long) pattern he chose was:
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
That posits to capture all of the following:
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.
So you'd use that pattern with something like preg_filter, and then iterate over the returned array of matches somehow. I guess. I hate regex.