HTML
|
|
|
|
<?php function url_hilight($str)
{
// lift all links, images and image maps
$url_tags = array (
"'<a[^>]*>.*</a>'si",
"'<map[^>]*>.*</map>'si",
"'<script[^>]*>.*</script>'si",
"'<style[^>]*>.*</style>'si",
"'<applet[^>]*>'si",
"'<object[^>]*>'si",
"'<embed[^>]*>'si",
"'<link[^>]*>'si",
"'<img[^>]*>'si"
);
foreach($url_tags as $url_tag)
{
preg_match_all($url_tag, $str, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$key = "<" . md5($match[0]) . ">";
$search[] = $key;
$replace[] = $match[0];
}
}
$str = str_replace($replace, $search, $str);
// indicate where urls end if they have these trailing special chars
$sentinals = array("'&(quot|#34);'i", // Replace html entities
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(d+);'e");
$str = preg_replace($sentinals, "<sentinal>\0<sentinal>", $str);
$vdom = "[:alnum:]"; // Valid domain chars
$vurl = $vdom."_~-"; // Valid subdomain and path chars
//$vura = "�-��-�!#$%&*+,;=@.".$vurl; // Valid additional parameters (after '?') chars;
$vura = "�-��-�!#$%&*+,;=@./".$vurl; // Valid additional parameters (after '?') chars;
// insert other local characters if needed
$protocol = "[[:alpha:]]{3,10}://"; // Protocol exp
$server = "([$vurl]+[.])*[$vdom]+"; // Server name exp
$path = "(([$vurl]+([.][$vurl]+)*/)|([.]{1,2}/))*"; // Document path exp (/.../)
$name = "[$vurl]+([.][$vurl]+)*"; // Document name exp
$params = "[?][$vura]*"; // Additional parameters (for GET)
$str = eregi_replace("$protocol$server(/$path($name)?)?($params)?", "<a href="\0">\0</a>", $str); // URL into links
$str = str_replace("<sentinal>", '', $str);
return str_replace($search, $replace, $str);
} ?>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|