/* $Id: searchhighlight.php,v 1.2 2004/01/16 09:37:43 pts00065 Exp $
$Log: searchhighlight.php,v $
Revision 1.2 2004/01/16 09:37:43 pts00065
Corrected case
Revision 1.1 2004/01/16 09:30:14 pts00065
highlight module
*/
function highlight_capture_start() {
ob_start();
}
function highlight_capture_stop() {
# q,sa_q google;p yahoo;text pmwiki
$ref_patterns=array("/^q=(.*)/","/^as_q=(.*)/","/^p=(.*)/","/^text=(.*)/");
$text = ob_get_clean();
$refer=preg_replace("/^.*\?(.*)/","$1",$_SERVER["HTTP_REFERER"]);
foreach ( explode ("&",$refer) as $qsa ) {
$words=preg_replace($ref_patterns,"$1",$qsa);
if ( $words != $qsa ) {
$words=preg_replace("/[\+\-\"\']/"," ",urldecode($words));
foreach ( explode (" ",$words) as $word ) {
if ( $word ) { # in case there where double spaces
highlight($text,$word) ;
}
}
}
}
echo $text;
}
function highlight(&$text,$word) {
$replace = "$word";
$splitted_text=preg_split ("/$word/i",$text); # explode would be faster but we need the i
for ( $i=0; $i]*$/",$splitted_text[$i] ) ) { # is the word in a html tag ?
array_splice($splitted_text,$i,2,$splitted_text[$i] . $word . $splitted_text[$i+1]);
}
}
$text=implode($replace,$splitted_text);
}
?>