Jump to content

Auto hyperlink


DragonFire-N[R]

Recommended Posts

You would use Regular expressions (RegEx), with the function preg_replace. Here is a somewhat simple example I wrote, it should work fine:

<?php

$text="www.phpfreaks.com is a great site, Look at www.phpfreaks.com/index.php?&foo=bar#baz";

$text = preg_replace(
"/(?:^|\b)((((http|https|ftp):\/\/)|(www\.))([\w\.]+)([,:%#&\/?=\w+\.-]+))(?:\b|$)/is",
"<a href=\"$1\" target=\"_blank\">$1</a>", $text);

print $text;

?>

Link to comment
https://forums.phpfreaks.com/topic/198882-auto-hyperlink/#findComment-1043958
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.