CKTIS / PHP
htmlspecialchars()
Maskiert HTML-Sonderzeichen beim Einfügen von Klartext.
Version: 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): stringMaskiert HTML-Sonderzeichen beim Einfügen von Klartext. ENT_QUOTES umfasst beide Anführungszeichen, ENT_SUBSTITUTE ersetzt ungültige Eingabefolgen. Gib die tatsächliche Zeichenkodierung an. Bei double_encode=false bleiben erkannte Entitäten einfach kodiert.
Signatur
htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
Ausgabe des Beispiels
A&B "Q" <tag> &
Beispiele
<?php
$text = "A&B \"Q\" <tag> &";
echo htmlspecialchars($text, ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401,"UTF-8",false);
Ergebnis
A&B "Q" <tag> &