a
     
 
       
   Developpeur web    
       
   Php Mysql et divers    
       
   Shitao    
   Sénèque    
   Recettes    
       


> Nettoyer l\'encodage windows cp1252 en ISO-88591 \"propre\"

Si vous avez des utilisateurs sous windows qui saisissent du contenu dans une interface qui l'insèr dans une base en ISO-88591 vous risquez d'avoir des surprises. Cette fonction permet de "nettoyer" l'encodage windows cp1552 en iso-88591 propre.



function purge_iso88591($str)
{
// adapté à partir de http://worldserver3.oleane.com/tthomas/jeucar.html
$cp1252_map = array(
"\\x80" => "euro", /* EURO SIGN */
"\\x82" => ",", /* SINGLE LOW-9 QUOTATION MARK */
"\\x83" => "f", /* LATIN SMALL LETTER F WITH HOOK */
"\\x84" => "'", /* DOUBLE LOW-9 QUOTATION MARK */
"\\x85" => "...", /* HORIZONTAL ELLIPSIS */
"\\x86" => "T", /* DAGGER */
"\\x87" => "T", /* DOUBLE DAGGER */
"\\x88" => "^", /* MODIFIER LETTER CIRCUMFLEX ACCENT */
"\\x89" => "p1000", /* PER MILLE SIGN */
"\\x8a" => "S", /* LATIN CAPITAL LETTER S WITH CARON */
"\\x8b" => "<", /* SINGLE LEFT-POINTING ANGLE QUOTATION */
"\\x8c" => "OE", /* LATIN CAPITAL LIGATURE OE */
"\\x8e" => "Z", /* LATIN CAPITAL LETTER Z WITH CARON */
"\\x91" => "'", /* LEFT SINGLE QUOTATION MARK */
"\\x92" => "'", /* RIGHT SINGLE QUOTATION MARK */
"\\x93" => '"', /* LEFT DOUBLE QUOTATION MARK */
"\\x94" => '"', /* RIGHT DOUBLE QUOTATION MARK */
"\\x95" => ".", /* BULLET */
"\\x96" => "-", /* EN DASH */
"\\x97" => "-", /* EM DASH */

"\\x98" => "", /* SMALL TILDE */
"\\x99" => "(tm)", /* TRADE MARK SIGN */
"\\x9a" => "s", /* LATIN SMALL LETTER S WITH CARON */
"\\x9b" => ">", /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
"\\x9c" => "oe", /* LATIN SMALL LIGATURE OE */
"\\x9e" => "z", /* LATIN SMALL LETTER Z WITH CARON */
"\\x9f" => "Y", /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/



"&euro;" => "euro", /* EURO SIGN */
"&#8364;" => "euro", /* EURO SIGN */

"&fnof;" => "f", /* LATIN SMALL LETTER F WITH HOOK */

"&hellip;" => "...", /* HORIZONTAL ELLIPSIS */
"&dagger;" => "T", /* DAGGER */
"&Dagger;" => "T", /* DOUBLE DAGGER */
"&circ;" => "^", /* MODIFIER LETTER CIRCUMFLEX ACCENT */
"&permil;" => "p1000", /* PER MILLE SIGN */
"&Scaron;" => "S", /* LATIN CAPITAL LETTER S WITH CARON */
"&#352;" => "S", /* LATIN CAPITAL LETTER S WITH CARON */

"&OElig;" => "OE", /* LATIN CAPITAL LIGATURE OE */
"&#338;" => "OE", /* LATIN CAPITAL LIGATURE OE */
"&#381;" => "Z", /* LATIN CAPITAL LETTER Z WITH CARON */
"&Zcaron;" => "Z", /* LATIN CAPITAL LETTER Z WITH CARON */
"&lsquo;" => "'", /* LEFT SINGLE QUOTATION MARK */
"&rsquo;" => "'", /* RIGHT SINGLE QUOTATION MARK */
"&ldquo;" => '"', /* LEFT DOUBLE QUOTATION MARK */
"&rdquo;" => '"', /* RIGHT DOUBLE QUOTATION MARK */
"&bull;" => ".", /* BULLET */
"&ndash;" => "-", /* EN DASH */
"&mdash;" => "-", /* EM DASH */

"&oline;" => "", /* SMALL TILDE */
"&trade;" => "(tm)", /* TRADE MARK SIGN */
"&scaron;" => "s", /* LATIN SMALL LETTER S WITH CARON */
"&#353;" => "s", /* LATIN SMALL LETTER S WITH CARON */

"&oelig;" => "oe", /* LATIN SMALL LIGATURE OE */
"&#339;" => "oe", /* LATIN SMALL LIGATURE OE */
"&zcaron;" => "z", /* LATIN SMALL LETTER Z WITH CARON */
"&#382;" => "z", /* LATIN SMALL LETTER Z WITH CARON */
"&Yuml;" => "Y" /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/


);

return strtr($str, $cp1252_map);
}




retour

  Tags : encodage


> Utiliser la librairie Iconv chez ovh en mutualisé
> Problème avec le caractère ' apostrophe (arrondie) transformé en ? par utf8_decode
> Détecter si une chaine est encodée en UTF-8
> Fonction inverse unhtmlentities et caractère "euro"
Cylman
  Tags : encodage


> Utiliser la librairie Iconv chez ovh en mutualisé
> Problème avec le caractère ' apostrophe (arrondie) transformé en ? par utf8_decode
> Détecter si une chaine est encodée en UTF-8
> Fonction inverse unhtmlentities et caractère "euro"



RSS    |    Mes liens    |    Syndication    |    Plan    |    Sitemap XML    |    Création de site web à Carcassonne