Jump to content

Better way?


frost

Recommended Posts

$Text = preg_replace("/(http[s]?){1}:\/\/([:a-z_\-\\.\/0-9%~]+){1}(\?[a-z=0-9\-_&;]*)?(\#[a-z0-9]+)?/", " <a href=\"$1://$2$3$4\">$1://$2$3$4</a>", $Text);

$Text = preg_replace('/\s(www\.)(\S+)/', ' <a href="http://\\1\\2" target="_blank">\\1\\2</a>', $Text);
echo stripslashes($Text);

 

I was able to slap together these 2 replacements for changing plain text links into active links. One finds all the text with http and the second finds the www text. I was wondering if there is a better way to do this?

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/69050-better-way/
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.