PHP: How to Gracefully deal with some Microsoft Windows Special Characters CodeUnit 22 JUN 2011

Although Microsoft Windows smart quotes are the usual culprits for web developers who need to display strings on devices powered by operating systems other than Windows, there are in fact a number of other Windows-only special characters that can potentially rear their heads every now and then.

Below is a handy list of string replaces (done verbosely for easier reading) that will replace these Windows special characters with accepted alternatives which can more easily be ported across to different systems:

 $str = str_replace(chr(130), ',', $str);    // baseline single quote
 $str = str_replace(chr(131), 'NLG', $str);  // florin
 $str = str_replace(chr(132), '"', $str);    // baseline double quote
 $str = str_replace(chr(133), '...', $str);  // ellipsis
 $str = str_replace(chr(134), '**', $str);   // dagger (a second footnote)
 $str = str_replace(chr(135), '***', $str);  // double dagger (a third footnote)
 $str = str_replace(chr(136), '^', $str);    // circumflex accent
 $str = str_replace(chr(137), 'o/oo', $str); // permile
 $str = str_replace(chr(138), 'Sh', $str);   // S Hacek
 $str = str_replace(chr(139), '<', $str);    // left single guillemet
 $str = str_replace(chr(140), 'OE', $str);   // OE ligature
 $str = str_replace(chr(145), "'", $str);    // left single quote
 $str = str_replace(chr(146), "'", $str);    // right single quote
 $str = str_replace(chr(147), '"', $str);    // left double quote
 $str = str_replace(chr(148), '"', $str);    // right double quote
 $str = str_replace(chr(149), '-', $str);    // bullet
 $str = str_replace(chr(150), '-', $str);    // endash
 $str = str_replace(chr(151), '--', $str);   // emdash
 $str = str_replace(chr(152), '~', $str);    // tilde accent
 $str = str_replace(chr(153), '(TM)', $str); // trademark ligature
 $str = str_replace(chr(154), 'sh', $str);   // s Hacek
 $str = str_replace(chr(155), '>', $str);    // right single guillemet
 $str = str_replace(chr(156), 'oe', $str);   // oe ligature
 $str = str_replace(chr(159), 'Y', $str);    // Y Dieresis

Should be useful.

Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.