this code highlight match word in search like this forum search
it is the same when i put it in my program in my localhost it works perfectly but in my site it didnt highlight any search word
the design of code like this
Code: Select all
<?
function phpbb_preg_quote($str, $delimiter)
{
$text = preg_quote($str);
$text = str_replace($delimiter, '\'' . $delimiter, $text);
return $text;
}
$highlight_match = $highlight = '';
if (isset($HTTP_GET_VARS['highlight']))
{
// Split words and phrases
$words = explode(' ', trim(htmlspecialchars(urldecode($HTTP_GET_VARS['highlight']))));
for($i = 0; $i < sizeof($words); $i++)
{
if (trim($words[$i]) != '')
{
$highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', phpbb_preg_quote($words[$i], '#'));
}
}
unset($words);
$highlight = urlencode($HTTP_GET_VARS['highlight']);
}
$message="hi all this is an example of my example ahmad";
if ($highlight_match)
{
// This was shamelessly 'borrowed' from volker at multiartstudio dot de
// via php.net's annotated manual
$message = str_replace('"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '<span style="color:#800000"><b>\\\\1</b></span>', '\\0')", '>' . $message . '<'), 1, -1));
}
echo $message;
?>u can see
$message="hi all this is an example of my example ahmad";
let we but this code in file with name highlight.php
when i open it , it print this message
but if i write
highlight.php?highlight=example+ahmad
it will print the message but any ahmad and example in the message with
diffrent color
ok this code work in my site and my localhost
but when i put it in my search program
Code: Select all
<?
include "header.php";
$highlight_match = $highlight = '';
if (isset($HTTP_GET_VARS['highlight']))
{
// Split words and phrases
$words = explode(' ', trim(htmlspecialchars(urldecode($HTTP_GET_VARS['highlight']))));
for($i = 0; $i < sizeof($words); $i++)
{
if (trim($words[$i]) != '')
{
$highlight_match .= (($highlight_match != '') ? '|' : '') . str_replace('*', '\w*', ahmad($words[$i], '#'));
}
}
unset($words);
$highlight = urlencode($HTTP_GET_VARS['highlight']);
}
if (!$op&&!$sec){
$head="ÎØÃ";
openTable();
echo "æÕæáß ÛíÑ ãÕÑÍ Èå";
closeTable();
}
if ($sec){
$head="ÇáßÊÈ ÇáãæÌæÏÉ Ýí åÐÇ ÇáÞÓã";
openTable();
$a1= mysql_query("select bkid , bkname from ".$prefix."books where secid=$sec");
if (mysql_num_rows($a1)==0){
echo "<br> áÇíæÌÏ ßÊÈ Ýí åÐÇ ÇáÞÓã";
}
$co=1;
while(list($bkid , $bkname) = mysql_fetch_row($a1)) {
echo "<tr><td >$co ) <a style="font-family: tahoma; font-size: 10pt; color: #800000" href="page.php?op=list&bk=$bkid">$bkname</a></td></tr>";
$co++;
}
closeTable();
}
/////////////////////////////////////////////////
if ($op=="list"){
$head="ãÍÊæíÇÊ ÇáßÊÇÈ";
openTable();
$a1= mysql_query("select fslname , fslid from ".$prefix."fsl where bkid=$bk order by fslid");
while(list( $fslname , $fslid) = mysql_fetch_row($a1)) {
if ($fslname!="ÝÕá ÊáÞÇÆí")
echo " <tr><td bgcolor="#FDD095" align="center" >$fslname</td></tr>";
$count=1;
$a2= mysql_query("select bksecid , bksecname from ".$prefix."bksections where fslid=$fslid");
while(list( $bksecid , $bksecname) = mysql_fetch_row($a2)) {
echo "<tr><td > $count ) <a href="page.php?op=show&boksecid=$bksecid">$bksecname</a> </td></tr>";
$count++;
}
}
if (mysql_num_rows($a1)==1 && mysql_num_rows($a2)==0){
echo "ÇáãÍÊæì ÝÇÑÛ";
}
closeTable();
}
///////////////////////////////////////////////////
//////////////////////////////////////////////////
if ($op=="show"){
$a4= mysql_query("select bksecname ,bksectex from ".$prefix."bksections where bksecid =$boksecid");
while(list( $bksecname , $bksectex) = mysql_fetch_row($a4)) {
$head=$bksecname;
openTableno();
if ($highlight_match)
{
$bksectex = str_replace('"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $highlight_match . ")\b#i', '<span style="color:#800000"><b>\\\\1</b></span>', '\\0')", '>' . $bksectex . '<'), 1, -1));
}
echo $bksectex;
}
closeTable();
}
//////////////////////////////////////////////////
include "footer.php";
?>but nothing happened in my site
could any one help me please
thanx