I have two characters that I need to do a search and replace on in a php-string.
’
“
Somehow these are different from:
'
"
Does anyone know what function I might use to strip these from a php string?
I have two characters that I need to do a search and replace on in a php-string.
’
“
Somehow these are different from:
'
"
Does anyone know what function I might use to strip these from a php string?
Check this out, I have been using it and it works:
How To Clean Special Characters From PHP String
Inside a PHP script saved as UTF-8 (so that these chars are correctly replresented), you can simply use
str_replace
to strip them.Why not just use
str_replace
?Of course, this requires your PHP scripts to be saved as UTF-8.
And if this doesn't work because those characters cannot be properly written using UTF-8, you'll have to fallback to using their hexadecimal representations.
For example :
(Not sure the hexadecimal values I used are really those of your two special quotes, though)
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.
What you have is called smart quotes, or curly quotes. There are people doing similar things. Chris Shiflett