Showing posts with label development. Show all posts
Showing posts with label development. Show all posts

Tuesday, January 22, 2008

Killing smart quote wierdness in PHP

Function to kill some weirdness caused by copying text from Microsoft Word to a textarea using raw UTF8 char codes.

The original function was posted here.


function convert_raw_utf8_smart_quotes($string)
{
$search = array(chr(0xe2) . chr(0x80) . chr(0x98),
chr(0xe2) . chr(0x80) . chr(0x99),
chr(0xe2) . chr(0x80) . chr(0x9c),
chr(0xe2) . chr(0x80) . chr(0x9d),
chr(0xe2) . chr(0x80) . chr(0x93),
chr(0xe2) . chr(0x80) . chr(0x94),
chr(0xe2) . chr(0x80) . chr(0xa6),
chr(0xe2) . chr(0x84) . chr(0xa2),
chr(0xc2) . chr(0xa9),
chr(0xc2) . chr(0xae),
chr(0xc2) . chr(0xa7));

$replace = array('‘',
'’',
'“',
'”',
'–',
'—',
'...',
'™',
'©',
'®',
'§');

return str_replace($search, $replace, $string);
}