search function puzzle..wots going on?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
getphp
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2004 12:18 pm

search function puzzle..wots going on?

Post 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;
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

highlites the matching values in red
getphp
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2004 12:18 pm

Post by getphp »

not sure if i understand what you mean?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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 >
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
getphp
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2004 12:18 pm

Post 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]
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

What kind of search script is that anyway ( me wondering .. )
getphp
Forum Newbie
Posts: 6
Joined: Tue Apr 06, 2004 12:18 pm

Post 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
Post Reply