Mark's Gravatar Mark's Profile

About Me:

Last 10 Comments

1

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('&lsquo;',
                   '&rsquo;',
                   '&ldquo;',
                   '&rdquo;',
                   '&ndash;',
                   '&mdash;');
                   
  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


Stats

  • Member Since: 16 May 2007
  • Comments: 1

Web Site

poisonkitty.livejournal.com

Blog Posts

Coming soon!