Re: Replacing whole words only

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

 



I'm also an idiot ...
Something else, the "or" output is occurring because the exception "the" matches "other " first so "other" becomes "or" minus the "the"...

So heres what I did ...

$search = array( '/\bthe\b/', '/\bother\b/', '/\bthat\b/', '/\ba\b/' );
$string = 'The other lady that laughed';

if( count( $search ) > 0 ) {
    foreach( $search as $exceptionPhrase ) {
      $string = preg_replace( strtolower($exceptionPhrase), '', strtolower($string)); 

    }
    $retval = trim( $string );

}
echo 'Retval: ' . $retval . '<br>';

And got 
lady laughed
In the matches ex. "/\bthe\b/" the \b mean word boundry so 
it matches only the whole word...
-David

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux