« Coder avec Unicode/Conversion » : différence entre les versions
Contenu supprimé Contenu ajouté
Ligne 23 :
!PHP !! print '<meta charset="UTF-8" />'; !! print '<meta charset="iso-8859-1" />';
|-
|-
| <source lang=php>print htmlentities($chaine);</source> || <source lang=html>é é $ €<br/></source> || <source lang=html>é é $ €<br/></source>
▲ $chaine = 'é é $ €<br/>';
|-
|-
| <source lang=php>print htmlspecialchars_decode($chaine);</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
|-
| <source lang=php>print utf8_decode($chaine);</source> || <source lang=html>é � $ ?</source> || <source lang=html>é é $ ?</source>
|-
| <source lang=php>print utf8_encode($chaine);</source> || <source lang=html>é é $ â¬</source> || <source lang=html>é é $ €</source>
|-
| <source lang=php>print htmlspecialchars($chaine);</source> || <source lang=html>é é $ €<br/></source> || <source lang=html>é é $ €<br/></source>
|-
| <source lang=php>print htmlentities($chaine, ENT_NOQUOTES, 'UTF-8');</source> || <source lang=html>é é $ €<br/></source> || <source lang=html>é é $ €<br/></source>
|-
| <source lang=php>print html_entity_decode($chaine, ENT_NOQUOTES, "UTF-8");</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
|-
| <source lang=php>print htmlspecialchars_decode(htmlentities($chaine, ENT_NOQUOTES, 'UTF-8'));</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
|-
| <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=html>é \u00e9 $ \u20ac</source> || <source lang=html></source>
|}
Ligne 81 ⟶ 61 :
{{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>).}}
== [[C]] ==
|