Page 1 of 1

Turn URLs into links

Posted: Wed Aug 02, 2006 8:33 pm
by Locust
I have my expression, but how do I convert

Code: Select all

http://www.url.com
into

Code: Select all

<a href=http://www.url.com>http://www.url.com</a>
I had a look everywhere but only found how to unlink URLs which was slightly different.

Code: Select all

$smessage = preg_replace('#^\w+://(www\.)?\w+\.\w+#','What should I put in here?',$smessage);

Posted: Wed Aug 02, 2006 8:35 pm
by feyd
Download phpbb. Look in bbcode.php for a function similar to make_clickable().

Posted: Wed Aug 02, 2006 8:42 pm
by Locust
Thanks feyd.

For others:

Code: Select all

$url = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $url);