Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2008, 11:20 AM   PM User | #1
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
how can php read + sign

i have this script
PHP Code:
function highlight($c,$q){
 
$q=explode('|',$q);
 for(
$i=0;$i<sizeOf($q);$i++){
 if (
strlen($q[$i])==1){
    
$c=eregi_replace('[[:<:]]' $q[$i] . '[[:>:]]'"<span class='z'>" .$q[$i]. "</span>"$c);}
 else {
    
$c=preg_replace("/($q[$i])(?![^<]*>)/i","<span class='z'>\${1}</span>",$c);
 }
   
 }
 return 
$c;

this code can highlight the search keyword.the problem is when i search c++ or C## only c is highlighted.i want to highlight the full word c++.please help me
meshi is offline   Reply With Quote
Old 02-20-2008, 09:22 PM   PM User | #2
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,503
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
Give this a shot:
PHP Code:
function highlight$c$q )
{
    
$q explode'|'$q );
    for ( 
$i 0$len count$q ); $i $len$i++ )
    {
        
$c preg_replace
        
(
            
'/(' preg_quote$q[$i], '/' ) . ')/Ui',
            
'<span class="z">\1</span>',
            
$c
        
);
    }
    return 
$c;

__________________
ZCE
kbluhm is offline   Reply With Quote
Users who have thanked kbluhm for this post:
meshi (02-21-2008)
Old 02-21-2008, 01:57 PM   PM User | #3
meshi
New Coder

 
Join Date: Aug 2007
Posts: 49
Thanks: 6
Thanked 1 Time in 1 Post
meshi is an unknown quantity at this point
thats really a good on one kbluhm..thanx in a million
meshi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.