« Coder avec Unicode/Conversion » : différence entre les versions
Contenu supprimé Contenu ajouté
Ligne 45 :
| <source lang=php>print mb_convert_encoding($chaine, 'HTML-ENTITIES', 'UTF-8');</source> || <source lang=html>é é $ €</source> || <source lang=html>...</source>
|-
| <source lang=php>print json_encode($chaine);</source
|-
| <source lang=php>print json_decode($chaine);</source> || <source lang=html></source> || <source lang=html>...</source>
Ligne 71 :
{{attention|Un <code>substr('aàb', 2, 1)</code> peut donner "à" car il compte pour deux caractères, pour avoir "b" il faut utiliser <code>mb_substr('aàb', 2, 1)</code> (pour ''multi-bytes substring''<ref>http://php.net/manual/fr/function.mb-substr.php</ref>).}}
{{remarque|Pour traiter les caractères Unicode considérés comme invalides dans les XML et JSON, utiliser preg_replace()<ref>https://magp.ie/2011/01/06/remove-non-utf8-characters-from-string-with-php/</ref>.}}
== [[C]] ==
|