Jump to content

URLs to Links


moon 111

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/107486-urls-to-links/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.