moon 111 Posted May 27, 2008 Share Posted May 27, 2008 I'm trying to write a regular expression to convert URLs found in a text into links. This is what I have right now (yes, I don't know what I'm doing): <?php $text = 'blah blah blah http://www.google.com asdasd'; $regex = '~((http://|https://)(?:www\.)?\w+\.[a-z]{2,4})~'; preg_replace($regex, '<a href="$1">$1</a>', $text); echo $text; ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/107486-urls-to-links/ Share on other sites More sharing options...
effigy Posted May 27, 2008 Share Posted May 27, 2008 Try this: http://www.phpfreaks.com/forums/index.php/topic,197080.msg889068.html Quote Link to comment https://forums.phpfreaks.com/topic/107486-urls-to-links/#findComment-551089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.