CKTIS / PHP
htmlspecialchars()
Codifica i caratteri speciali HTML quando si inserisce testo semplice.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): stringCodifica i caratteri speciali HTML quando si inserisce testo semplice. ENT_QUOTES comprende le due virgolette ed ENT_SUBSTITUTE sostituisce le sequenze non valide. Indica la codifica effettiva. Con double_encode=false le entità riconosciute restano codificate una volta sola.
Firma
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
Output dell’esempio
A&B "Q" <tag> &
Esempi
<?php
$text = "A&B \"Q\" <tag> &";
echo htmlspecialchars($text, ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401,"UTF-8",false);
Risultato
A&B "Q" <tag> &