« 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>$chaine = '&eacute é $ €<br/>';</source> ||
|-
<source lang=php>
| <source lang=php>print htmlentities($chaine);</source> || <source lang=html>&eacute é $ €<br/></source> || <source lang=html>&eacute é $ €<br/></source>
$chaine = '&eacute é $ €<br/>';
|-
print htmlentities($chaine);
| <source lang=php>print html_entity_decode($chaine);</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
|-
print htmlspecialchars_decode($chaine);
| <source lang=php>print htmlspecialchars_decode($chaine);</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
print utf8_decode($chaine);
|-
print utf8_encode($chaine);
| <source lang=php>print utf8_decode($chaine);</source> || <source lang=html>é � $ ?</source> || <source lang=html>é é $ ?</source>
print htmlspecialchars($chaine);
|-
print htmlentities($chaine, ENT_NOQUOTES, 'UTF-8');
| <source lang=php>print utf8_encode($chaine);</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
print html_entity_decode($chaine, ENT_NOQUOTES, "UTF-8");
|-
print htmlspecialchars_decode(htmlentities(
| <source lang=php>print htmlspecialchars($chaine);</source> || <source lang=html>&eacute é $ €<br/></source> || <source lang=html>&eacute é $ €<br/></source>
$chaine, ENT_NOQUOTES, 'UTF-8'));
|-
print mb_convert_encoding($chaine, 'HTML-ENTITIES', 'UTF-8');
| <source lang=php>print htmlentities($chaine, ENT_NOQUOTES, 'UTF-8');</source> || <source lang=html>&eacute é $ €<br/></source> || <source lang=html>&eacute é $ €<br/></source>
</source>
|-
|style="vertical-align: text-top;"|
| <source lang=php>print html_entity_decode($chaine, ENT_NOQUOTES, "UTF-8");</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
<source lang=html4strict>
|-
 
| <source lang=php>print htmlspecialchars_decode(htmlentities($chaine, ENT_NOQUOTES, 'UTF-8'));</source> || <source lang=html>é é $ €</source> || <source lang=html>é é $ €</source>
&eacute é $ €<br/>
|-
é é $ €
| <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>
é é $ €
&eacute é $ €<br/>
&eacute é $ €<br/>
é é $ €
é é $ €
 
é é $ €
</source>
|style="vertical-align: text-top;"|
<source lang=html4strict>
 
&eacute é $ €<br/>
é é $ €
é é $ €
é é $ ?
é é $ €
&eacute é $ €<br/>
&eacute é $ €<br/>
é é $ €
é é $ €
</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>).}}
 
{{à faire|Quelle suite d'encodage(s) affiche "\u008e" pour "é" ?}}
 
== [[C]] ==