Re: preg_replace - What is wrong here?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks a lot for your message Jony dos Santos Kostetzer and José Miguel 
Santibáñez, actually that @ was my mistake, I got to solve it this way:

function MarkWords($profile_text, $words){
    for($i=0; $i<count($words); $i++){
        $patern[$i] = "@".$words[$i]."@i";
        $replace[$i] = "<span 
style='color:white'>".$words[$i]."</span>";   
    }   
    $pro = preg_replace($patern, $replace, $profile_text);           
    return $pro;
}

But I am not happy because if I do this:
$words = array('PEACE','people');
$profile_text = "I would like to meet People to help me to work in the 
world Peace project.";
$marked = MarkWords($profile_text, $words);

This will return  (marked of course)
"I would like to meet people to help me to work in the world PEACE project."

But I would like to keep the orignal word and change just the color.


Jony dos Santos Kostetzer escreveu:

> Hi Fransciso,
>
> Why did you use @? If you remove it, preg works correctly. If you want 
> match
> only complete words, use  $patern[$i] = "/\b".$words[$i]."\b/";
>
> Regards from Brazil =D
>
> Jony dos Santos Kostetzer
> A2C Internet - R&D
>
> Em Ter 28 Mar 2006 19:47, Francisco - São Paulo - Brazil escreveu:
> > Suppose I have this:
> >
> >  $words = array('piece','people');
> >  $profile_text = "I would like to meet people to help me to work in the
> >  world piece project.";
> >
> >  $marked = MarkWords($profile_text, $words);
> >
> >  Should return the same sentece but with the 2 words replaced with the
> >  <span> tag, am I wrong?
> >
> >  function MarkWords($profile_text, $words){
> >      for($i=0; $i<count($words); $i++){
> >          $patern[$i] = "/@".$words[$i]."/";
> >          $replace[$i] = "<span
> >  style='color:white'>".$words[$i]."</span>";  
> >      }
> >     // print_r($patern);
> >     // print_r($replace);
> >    
> >      $pro = preg_replace($patern, $replace, $profile_text);          
> >      return $pro;
> >  }
>
> -- 
>
>
> PHP Data object relational mapping generator
> http://www.metastorage.net/
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
>     *  Visit your group "php-objects
>       <http://groups.yahoo.com/group/php-objects>" on the web.
>        
>     *  To unsubscribe from this group, send an email to:
>        php-objects-unsubscribe@xxxxxxxxxxxxxxx
>       <mailto:php-objects-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>        
>     *  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>
>------------------------------------------------------------------------
>
>Internal Virus Database is out-of-date.
>Checked by AVG Free Edition.
>Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date: 09/12/2005
>
>  
>

-- 
/*----------------------------*/
    When you have a hammer 
 Everything looks like a nail.
/*----------------------------*/



PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux