views:

27

answers:

2

i have a lil problem here..i'm using str_replace to replace the most common words..and for some reason its replacing every letter except caps.

for example..if i had the code below

$str ="Fat string of Text.";    
$commonwords = array('fat','of','random');
$cleantext = str_replace($commonwords,'',$str);

echo $cleantext;

it would echo.. F T

any ideas what i did wrong.. thanks in advance

and oh..i tried str_ireplace.. but nothing

+4  A: 

This echos "Fat string Text".

Your PHP installation may be wrong or your posted code that does not exactly match the program you are running

Also, str_ireplace echos "string Text".

Mark
found the proble'm..some of the words in my array were like-> i've,can't <-- the apostrophes were making the problem..thanks for the help
andrewk
Yup, escape your apostrophes :)
Mark
A: 

Can't reproduce that on PHP 5.3.3. I get:

php > $str ="Fat string of Text.";
php > $commonwords = array('fat','of','random');
php > $cleantext = str_replace($commonwords,'',$str);
php > echo $cleantext;
Fat string  Text.
php > $cleantext = str_ireplace($commonwords,'',$str);
php > echo $cleantext;
 string  Text.

as expected.

Matthew Flaschen