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);

i didn't make any changes to your code and got a parse error on line 12. The one with the if statment in the while(). you need to work on that.

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<strlen($Text)){ 
				if((($i + strlen($Needle[$j])) <= strlen($Text)) && (strcasecmp($Needle[$j], substr($Text, $i, strlen($Needle[$j]))) == 0)) { 
					$TextTemp .= '<font style="background-color:#FFFF00">' . substr($Text, $i , strlen($Needle[$j])) . '</font>'; 
					$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);

please use above code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.