Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post

    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

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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;


  • Users who have thanked kbluhm for this post:

    meshi (02-21-2008)

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    49
    Thanks
    6
    Thanked 1 Time in 1 Post
    thats really a good on one kbluhm..thanx in a million


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •