Page 1 of 1

search function puzzle..wots going on?

Posted: Tue Apr 06, 2004 12:18 pm
by getphp
I am have downloaded a search function and it seems to work wonders but How is the bottom code working within the search file?
Can someone help me understand exactly what the function below is doing.
Note: this is just a small part of the whole search.php file

Code: Select all

function hl($str) { 
    GLOBAL $lq; 
    $str=" ".$str; 

    $ph=explode(" ",$lq); 
    $lstr=mysql_result(mysql_query("SELECT lower('$str')"),0,0); 

    for ($i=0;$i<count($ph);$i++) &#123; 
        $lstr=eregi_replace($ph&#1111;$i],"<b><font color=red>".$ph&#1111;$i]."</font></b>",$lstr); 
        &#125; 
     
    $p1=1;$p2=1; 
    while ($p1!=0 && $p2!=0) &#123; 
        if (($p1=strpos($lstr,"<b><font color=red>"))!=0) &#123; 
            $lstr&#1111;$p1]="|"; 
            $str=substr($str,0,$p1)."<b><font color=red>".substr($str,$p1); 

            if (($p2=strpos($lstr,"</font></b>"))!=0) &#123; 
                $lstr&#1111;$p2]="|"; 
                $str=substr($str,0,$p2)."</font></b>".substr($str,$p2); 
                &#125; 
            &#125; 
        &#125; 

    $str=substr($str,1); 
    return($str); 
    &#125;

Posted: Tue Apr 06, 2004 12:35 pm
by lostboy
highlites the matching values in red

Posted: Tue Apr 06, 2004 12:47 pm
by getphp
not sure if i understand what you mean?

Posted: Tue Apr 06, 2004 1:38 pm
by McGruff
It will (presumably) highlight search terms in red.

< font > tags are deprectaed however: might want to edit the fn, replacing these with < span style="color:red; font-weight: bold;"> and < /span >

Posted: Tue Apr 06, 2004 2:20 pm
by Weirdan

Code: Select all

...
$lstr=mysql_result(mysql_query("SELECT lower('$str')"),0,0);
...
I wonder if the author of that script ever heard about [php_man]strtolower[/php_man] function.

Posted: Tue Apr 06, 2004 3:06 pm
by getphp
thanks for ur replies guys!!

Though What is the WHILE function doing?

ok so it makes sense..I guess it will take the search term and when results are displayed it will display the search term in red.
Thanks :)[/b]

Posted: Tue Apr 06, 2004 3:33 pm
by ol4pr0
What kind of search script is that anyway ( me wondering .. )

Posted: Wed Apr 07, 2004 7:21 am
by getphp
it is actually from a program called 'cncat', which i am trying to understand to improve my understanding of how it is working