Jump to content

Recommended Posts

 

I have enclosed the simple PHP function for Text [array] Highlight

 

without changing the own case...

 

 

 

 

function ShowPowerHighlight($Text,$Needle) {

    for($j=0; $j< count($Needle); $j++){ 

        if ($Needle[$j] != "") { 

            $TextTemp = ""; 

            $i=0; 

            while($i if((($i + strlen($Needle[$j])) <= strlen($Text)) 

&&             (strcasecmp($Needle[$j], substr($Text, $i, 

strlen($Needle[$j]))) == 0)) { 

                 $TextTemp .= '' . substr($Text, $i , 

strlen($Needle[$j])) . '';

                 $i += strlen($Needle[$j]); 

        }else {  

                 $TextTemp .= $Text{$i}; 

                 $i++; 

         } 

     } 

          $Text = $TextTemp; 

          $TextTemp="";

     }

   } 

      return $Text; 

  }

$Text= "The PHP Hypertext Preprocessor is a programming language that 

allows web developers to create dynamic content that interacts with 

databases" ;



$Needle= array ("0" =>"PHP","1"=>"web","2"=>"to","3"=>"byet"); 

echo ShowPowerHighlight($Text,$Needle);

Link to comment
https://forums.phpfreaks.com/topic/76977-php-searchtext-highlight-function/
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.