/* $Id: searchhighlight.php,v 1.4 2004/01/16 10:38:19 pts00065 Exp $
$Log: searchhighlight.php,v $
Revision 1.4 2004/01/16 10:38:19 pts00065
The case thing wasn't that easy
Revision 1.3 2004/01/16 10:09:23 pts00065
Added:
vinden.nl
ilse.nl
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("/^search_for=(.*)/","/^query=(.*)/","/^q=(.*)/","/^as_q=(.*)/","/^p=(.*)/","/^text=(.*)/");
$text = ob_get_clean();
$refer=preg_replace("/^.*\?(.*)/","$1",$_SERVER["HTTP_REFERER"]);
#$refer="q=Kaasfondue+site:www.brambring.nl&num=20&hl=en&lr=lang_nl|lang_en&ie=UTF-8&oe=UTF-8&start=20&sa=N";
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/",$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]);
$i--;
}
}
$text=implode($replace,$splitted_text);
}
?>