1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <code class = "php" > function convert_smart_quotes( $string )
{
$unicode_map = array (
"\xC2\xAB" => "'" ,
"\xC2\xBB" => "'" ,
"\xE2\x80\x98" => "'" ,
"\xE2\x80\x99" => "'" ,
"\xE2\x80\x9A" => "'" ,
"\xE2\x80\x9B" => "'" ,
"\xE2\x80\x9C" => '"' ,
"\xE2\x80\x9D" => '"' ,
"\xE2\x80\x9E" => '"' ,
"\xE2\x80\x9F" => '"' ,
"\xE2\x80\xB9" => "'" ,
"\xE2\x80\xBA" => "'" ,
"\xC2\x82" => "'" ,
"\xC2\x84" => '"' ,
"\xC2\x8B" => "'" ,
"\xC2\x91" => "'" ,
"\xC2\x92" => "'" ,
"\xC2\x93" => '"' ,
"\xC2\x94" => '"' ,
"\xC2\x9B" => "'"
);
$html_entities = array (
"&#8216;" => "'" ,
"&#8217;" => "'" ,
"&#8220;" => '"' ,
"&#8221;" => '"'
);
$windows_cp1252 = array (
"&lsquo;" => "'" ,
"&rsquo;" => "'" ,
"&ldquo;" => '"' ,
"&rdquo;" => '"' ,
"&mdash;" => ' - ' ,
"&ndash;" => '- '
);
$string = str_replace (
array_keys ( $unicode_map ),
array_values ( $unicode_map ),
html_entity_decode( $string , ENT_QUOTES, "UTF-8" )
);
$string = str_replace (
array_keys ( $windows_cp1252 ),
array_values ( $windows_cp1252 ),
$string
);
$string = str_replace (
array_keys ( $html_entities ),
array_values ( $html_entities ),
$string
);
return $string ;
}</code>
|