CKTIS / PHP
htmlspecialchars()
Escape HTML-tekens bij het invoegen van platte tekst.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): stringEscape HTML-tekens bij het invoegen van platte tekst. ENT_QUOTES omvat beide soorten aanhalingstekens en ENT_SUBSTITUTE vervangt ongeldige invoerreeksen. Geef de werkelijke codering op. Met double_encode=false blijven herkende entiteiten eenmaal gecodeerd.
Signatuur
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
Uitvoer van het voorbeeld
A&B "Q" <tag> &
Voorbeelden
<?php
$text = "A&B \"Q\" <tag> &";
echo htmlspecialchars($text, ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401,"UTF-8",false);
Resultaat
A&B "Q" <tag> &