ereg? NO! :-D
here's my function again that i posted here. works great, is super fast with the preg functions, and does e-mail addresses, too. if you don't want e-mail addresses done, remove the the first line of the make_clickable() function. usage: `$txt = make_clickable($txt);' :-)
Code:
function make_clickable($txt)
{
$txt = preg_replace('#([^\w=+;%?/]|^)(\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,4})#i', '$1<a href="mailto:$2">$2</a>', $txt);
$txt = preg_replace('#([^\w/@]|^)((?:www\.[\w-]+\.[\w-]+?\S*?)|(?:[a-z]{3,6}://\S+?))(?=[^a-z0-9/]*?(?:[\s<\][]|(?:&(?:quot|lt|gt);)|$))#ei', 'create_link("$1", "$2")', $txt);
return $txt;
}
function create_link($pre, $url)
{
// these 2 lines fix any apostrophes that get
// messed up by being passed to the function
$pre = str_replace("\\'", "'", $pre);
$url = str_replace("\\'", "'", $url);
$suf = '';
if (preg_match('/&amp$/', $url))
{
$suf = '&amp';
$url = substr($url, 0, -4);
}
$html_url = $url;
if (!preg_match('#^[a-z]{3,6}://#i', $html_url)) { $html_url = "http://$url"; }
return "$pre<a href=\"$html_url\" target=\"_blank\">$url</a>$suf";
}
Bookmarks