CKTIS / PHP
htmlspecialchars()
Échappe les caractères spéciaux HTML lors de l’insertion de texte brut.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): stringÉchappe les caractères spéciaux HTML lors de l’insertion de texte brut. ENT_QUOTES inclut les deux guillemets et ENT_SUBSTITUTE remplace les séquences invalides. Indiquez le codage réel. Avec double_encode=false, les entités reconnues restent encodées une seule fois.
Signature
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
Sortie de l’exemple
A&B "Q" <tag> &
Exemples
<?php
$text = "A&B \"Q\" <tag> &";
echo htmlspecialchars($text, ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401,"UTF-8",false);
Résultat
A&B "Q" <tag> &