htmlspecialchars_decode()
htmlspecialchars_decode() — Convert special HTML entities back to characters.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters.
Signature
htmlspecialchars_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string to decode. |
| $flags | int | A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use. The default is ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. Available flags constants Constant Name Description ENT_COMPAT Will convert double-quotes and leave single-quotes alone. ENT_QUOTES Will convert both double and single quotes. ENT_NOQUOTES Will leave both double and single quotes unconverted. ... |
Return value
Returns the decoded string.
Example
A runnable snippet:
$str = "<p>this -> "</p>\n"; echo htmlspecialchars_decode($str); // note that here the quotes aren't converted echo htmlspecialchars_decode($str, ENT_NOQUOTES);
Output:
<p>this -> "</p> <p>this -> "</p>
Changelog
| Version | Change |
|---|---|
| 8.1.0 | flags changed from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. |
See also
htmlspecialchars(), html_entity_decode(), get_html_translation_table()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page htmlspecialchars_decode() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.