remove a list of words from a string
Posted: Wed Jun 03, 2009 5:56 am
Hi,
I'd like to remove all aaa and bbb (whole word) from my string. I use the code below:
$str=" aaa bbb aaa aaa aaa laaa bbb ";
echo preg_replace("/\s(aaa|bbb)\s/", ' ', $str);
The output is " bbb aaa laaa ".
-->bbb and aaa are still there while it must be removed?
What's wrong with the pattern I used?
(The pattern above works fine if I replace \s by \b - but I don't want to use \b because \b does not work as expected if my string $str contains unicode words).
Could somebody please help me solve the issue?
I'd like to remove all aaa and bbb (whole word) from my string. I use the code below:
$str=" aaa bbb aaa aaa aaa laaa bbb ";
echo preg_replace("/\s(aaa|bbb)\s/", ' ', $str);
The output is " bbb aaa laaa ".
-->bbb and aaa are still there while it must be removed?
What's wrong with the pattern I used?
(The pattern above works fine if I replace \s by \b - but I don't want to use \b because \b does not work as expected if my string $str contains unicode words).
Could somebody please help me solve the issue?