User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,745 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 770 | Replies: 3
Reply
Join Date: Sep 2007
Location: India
Posts: 8
Reputation: sujithfem is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sujithfem sujithfem is offline Offline
Newbie Poster

Solution PHP-SearchText Highlight Function

  #1  
Nov 12th, 2007
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);
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 71
kkeith29's Avatar
kkeith29 kkeith29 is online now Online
Practically a Master Poster

Re: PHP-SearchText Highlight Function

  #2  
Nov 12th, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Location: India
Posts: 8
Reputation: sujithfem is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sujithfem sujithfem is offline Offline
Newbie Poster

Troubleshooting Re: PHP-SearchText Highlight Function

  #3  
Nov 12th, 2007
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);
"The fear of the Lord is the beginning of wisdom"
Reply With Quote  
Join Date: Sep 2007
Location: India
Posts: 8
Reputation: sujithfem is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sujithfem sujithfem is offline Offline
Newbie Poster

Re: PHP-SearchText Highlight Function

  #4  
Nov 12th, 2007
please use above code
"The fear of the Lord is the beginning of wisdom"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC