← All built-ins / htmlspecialchars()

htmlspecialchars()

htmlspecialchars(string $s): string

Parameters

NameTypeDescription
$sstringtext to escape

Return value

The text with only the five HTML-critical characters (& " ' < >) escaped.

Example

echo htmlspecialchars("<a href=\"x\">link</a>");
&lt;a href=\"x\"&gt;link&lt;/a&gt;

See also

htmlentities()html_entity_decode()