function url_hilight($str) { // lift all links, images and image maps $url_tags = array ( "']*>.*'si", "']*>.*'si", "']*>.*'si", "']*>.*'si", "']*>'si", "']*>'si", "']*>'si", "']*>'si", "']*>'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, "\0", $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)?", "\0", $str); // URL into links $str = str_replace("", '', $str); return str_replace($search, $replace, $str); }