CWCJimmy
04-21-2006, 10:10 AM
$titlehigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'field1' ] );
$linkhigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'field2' ] );
$linkdesc = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'field3' ] );
foreach($trimmed_array as $trimm){
if($trimm != 'b' ){
//IF you added more fields to search make sure to add them below as well.
$titlehigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $titlehigh);
$linkhigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkhigh);
$linkdesc = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkdesc);
This code is a snippet from this page: http://www.devpapers.com/article/306
I'm trying to write a searching component for my site in PHP. I know the idea is to search the values pulled from the database and "highlight" the keywords input into the search box, but I don't understand how this is doing it. I'm unfamiliar with the 'si' and the '\\1' pieces in this code and can't seem to find much on them.
Can anyone explain or direct me to an explanation?
Thanks!
$linkhigh = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'field2' ] );
$linkdesc = preg_replace ( "'($var)'si" , "<b>\\1</b>" , $row_linkcat[ 'field3' ] );
foreach($trimmed_array as $trimm){
if($trimm != 'b' ){
//IF you added more fields to search make sure to add them below as well.
$titlehigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $titlehigh);
$linkhigh = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkhigh);
$linkdesc = preg_replace( "'($trimm)'si" , "<b>\\1</b>" , $linkdesc);
This code is a snippet from this page: http://www.devpapers.com/article/306
I'm trying to write a searching component for my site in PHP. I know the idea is to search the values pulled from the database and "highlight" the keywords input into the search box, but I don't understand how this is doing it. I'm unfamiliar with the 'si' and the '\\1' pieces in this code and can't seem to find much on them.
Can anyone explain or direct me to an explanation?
Thanks!