Page 1 of 1

URL pattern for wrapping links

Posted: Sat Nov 29, 2008 6:14 am
by Eran
I'm looking for a pattern that can match URL addresses in order to wrap them with an anchor tag. Something like:

Code: Select all

preg_replace($pattern, '<a href="$1">$1</a>', $text);
Where the pattern could match any simple URL address, with or without the protocol. Somehow I'd figured I could google my way to this, but have been failing miserably.

Re: URL pattern for wrapping links

Posted: Sat Nov 29, 2008 10:34 am
by GeertDD
Here is an auto_link_urls() function I wrote: http://dev.kohanaphp.com/browser/trunk/ ... t.php#L243

Re: URL pattern for wrapping links

Posted: Sat Nov 29, 2008 10:41 am
by omniuni
Nice! I bookmarked that!

Re: URL pattern for wrapping links

Posted: Sat Nov 29, 2008 11:31 am
by Eran
Thanks a lot! just what I was looking for :)