PHP htmlspecialchars_decode()
Anonymous contributor
Published Sep 20, 2023
Contribute to Docs
The htmlspecialchars_decode() function converts special HTML entities back to characters. The converted entities include &, ", ', < and >.
Syntax
htmlspecialchars_decode($string, $flags)
The htmlspecialchars_decode() function has two parameters:
$string(required): Specifies the string with the HTML entities to convert (decode).$flags(optional): A bitmask of one or more of the following flags, which specify how to handle quotes and which document type to use.
| Constant | Description |
|---|---|
ENT_COMPAT |
Converts double-quotes and leaves single-quotes alone |
ENT_QUOTES |
Converts both double and single quotes |
ENT_NOQUOTES |
Leaves both double and single quotes unconverted |
ENT_SUBSTITUTE |
Replaces invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or � (otherwise) instead of returning an empty string |
ENT_HTML401 |
Handles code as HTML 4.01 |
ENT_XML1 |
Handles code as XML 1 |
ENT_XHTML |
Handles code as XHTML |
ENT_HTML5 |
Handles code as HTML 5 |
The htmlspecialchars_decode() function returns the converted string with characters like &, ", ', < and >.
Example
The following example uses the htmlspecialchars_decode() function to convert a string that contains multiple HTML entities.
<?php$original = "Codecademy <3 PHP and special characters like &, ", ', < and >.";echo "original: " . $original . "\n";echo "converted: " . htmlspecialchars_decode($original, ENT_QUOTES) . "\n";?>
The example will result in the following output:
original: Codecademy <3 PHP and special characters like &, ", ', < and >.converted: Codecademy <3 PHP and special characters like &, ", ', < and >.
Codebyte Example
This example is runnable and uses the htmlspecialchars_decode() function:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PHP on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours