str_replace() not doing what I'd like

Hello,


$raw = "That's a sentence.";
$format = "<p>That's a sentence.</p>";

str_replace($raw,$format,$content);

where $content is a TEXT from a db.

The replacement isn’t occuring. Yet I tried to cut and paste $raw both from the db AND from the source of the html page outputed after formatting. None solution worked.

If I remove the first part of the sentence (that is: That’) then it works. So the problem lies somewhere in that string “That’”.

What could it be?

Regards,

-jj. :slight_smile:

What exactly does your $content variable contain?

If it’s db content, most likely your single quote is escaped with backslash so try either using \’ instead of ’ or strip the escaped slashes.

I agree with furicane it’s probably your quote thats messing it up.

You should paste the $content variable in here so we can tell your for sure.

Thanks a lot for your replies.

@Salathe: $content contains a wordpress post using get_the_content();
@furicane: When I echo $content, I see the sentence exactly as I posted it above. The strangest thing is that the code above is repeated many times (there are many sentences I want to “format”) and some sentences like the one I posted above, some with “'”, are just working fine.