PHP: Handle Microsoft Windows Smart Quotes in Your Strings CodeUnit 04 JUL 2011

Microsoft Word likes converting single and double quotes into it’s so-called smart quotes representation, which can be annoying when you are trying to display the string on a device that doesn’t support smart quotes (the curly ones in case you were wondering). The easiest way to clean out these curly smart or fancy quotes is to run a simple search and replace on your string:

 $text = "string containing Microsoft Smart Quotes...";
 $chrs = array (chr(150), chr(147), chr(148), chr(146));
 $repl = array ("-", """, """, "'");
 $text = str_replace($chrs, $repl, $text);

And now you know.

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.