You are in: home / community
About Me:
After doing a hex dump of some incoming data that contained smart quotes, I noticed 3-byte sequences that represented the UTF-8 quotes. Here's a modified version of your function for dealing with UTF-8 smart quotes: <?php 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)); $replace = array('‘', '’', '“', '”', '–', '—'); return str_replace($search, $replace, $string); } ?> I found a good ASCII table here: http://www.manderby.com/mandalex/a/ascii.phpPosted in /blog/2005/oct/convert-smart-quotes-with-php. Wed, 16 May 2007 at 12:40:56: Link
After doing a hex dump of some incoming data that contained smart quotes, I noticed 3-byte sequences that represented the UTF-8 quotes. Here's a modified version of your function for dealing with UTF-8 smart quotes:
<?php 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)); $replace = array('‘', '’', '“', '”', '–', '—'); return str_replace($search, $replace, $string); } ?>
<?php
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));
$replace = array('‘',
'’',
'“',
'”',
'–',
'—');
return str_replace($search, $replace, $string);
}
?>
I found a good ASCII table here: http://www.manderby.com/mandalex/a/ascii.php
Posted in /blog/2005/oct/convert-smart-quotes-with-php.
Wed, 16 May 2007 at 12:40:56: Link
poisonkitty.livejournal.com
Coming soon!
Last 10 Comments
1