views:

297

answers:

1

I'm trying to get rid of curly apostrophes (ones pasted from some sort of rich text doc, I imagine) and I seem to be hitting a road block. The code below isn't working for me.

$word = "Today’s";
$search = array('„', '“', '’');
$replace = array('"', '"', "'");
$word = str_replace($search, $replace, htmlentities($word, ENT_QUOTES));

What I end up with is $word containing 'Today’s'.

When I remove the ampersands from my $search array, the replace takes place but this, obviously, will not get the job done since the ampersand is left in the string. Why is str_replace failing when it comes across the ampersands?

+3  A: 

Why not just do this:

$word = htmlentities(str_replace($search, $replace, $word), ENT_QUOTES);

?

cletus
Wow, that was incredibly easy. I think I've been coding for too long!
Anthony