I have two characters that I need to do a search and replace on in a php-string.

  1. ’
  2. “

Somehow these are different from:

  1. '
  2. "

Does anyone know what function I might use to strip these from a php string?

Comments

The first two aren't in ASCII. They're (in)famous as "smart/fancy quotes", mainly come from a certain office suite *cough* and aren't a problem if your website specifies in a certain encoding - which sadly is incompatible with Unicode though. (Now, to be fair, there should be equivalents in Unicode - propably what SO uses right now)

Written by delnan

this lovely characters have been a major encoding pain for me during a very long period.

Written by amosrivera

If you're dealing with those characters, you'll probably also encounter that en dash (–), too. Pretty annoying if you're not using UTF-8.

Written by Dan Breen

Accepted Answer

That's what happens when someone sends you an email in outlook, so watch out, because you're totally missing the opening pair of those single quotes, and closing pair for the double quotes. But really, you need to be using html entity codes.

Why? Because there's a hell of a lot more out there in the wilderness than those two codes you posted above, in-fact, you've only shown half the set of quotes (ie, you missed the closing single quote, and opening double quote). There's hundreds, you need to be encoding them in a better way than string replace.

There's a couple ways to manage the translation from encoding to html entity.

http://php.net/manual/en/function.htmlentities.php

http://piology.org/entities.html

http://konieczny.be/unicode.html

There's more also, but they basically do the same thing.

Written by Incognito
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki