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
getphp
Forum Newbie
Posts: 6 Joined: Tue Apr 06, 2004 12:18 pm
Post
by getphp » Tue Apr 06, 2004 12:18 pm
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++) {
$lstr=eregi_replace($phї$i],"<b><font color=red>".$phї$i]."</font></b>",$lstr);
}
$p1=1;$p2=1;
while ($p1!=0 && $p2!=0) {
if (($p1=strpos($lstr,"<b><font color=red>"))!=0) {
$lstrї$p1]="|";
$str=substr($str,0,$p1)."<b><font color=red>".substr($str,$p1);
if (($p2=strpos($lstr,"</font></b>"))!=0) {
$lstrї$p2]="|";
$str=substr($str,0,$p2)."</font></b>".substr($str,$p2);
}
}
}
$str=substr($str,1);
return($str);
}
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Tue Apr 06, 2004 12:35 pm
highlites the matching values in red
getphp
Forum Newbie
Posts: 6 Joined: Tue Apr 06, 2004 12:18 pm
Post
by getphp » Tue Apr 06, 2004 12:47 pm
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 » Tue Apr 06, 2004 1:38 pm
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 >
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Apr 06, 2004 2:20 pm
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 » Tue Apr 06, 2004 3:06 pm
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]
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue Apr 06, 2004 3:33 pm
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 » Wed Apr 07, 2004 7:21 am
it is actually from a program called 'cncat', which i am trying to understand to improve my understanding of how it is working