PHP htmlspecialchars_decode()Functions
Example
Convert the predefined HTML entities "<" (less than) and ">" (greater than) to characters:
The HTML output of the above code is as follows (view source code):
The browser output of the above code is as follows:
Definition and Usage
The htmlspecialchars_decode() function converts some predefined HTML entities to characters.
The HTML entities that will be decoded are:
- & decodes to & (ampersand)
- " decodes to " (double quote)
- ' decodes to ' (single quote)
- < decodes to < (less than)
- > decodes to > (greater than)
The htmlspecialchars_decode() function ishtmlspecialchars()the inverse function of the htmlspecialchars() function.
Syntax
| Parameter | Description |
|---|---|
| string | Required. Specifies the string to decode. |
| flags | Optional. Specifies how to handle quotes and which document type to use. Available quote types:
Additional flags specifying the document type used:
|
Technical Details
| Return value: | Returns the converted string. |
|---|---|
| PHP Version: | 5.1.0+ |
| Changelog: | In PHP 5.4, additional flags for specifying the document type were added: ENT_HTML401, ENT_HTML5, ENT_XML1, and ENT_XHTML. |
More Examples
Example 1
Convert some predefined HTML entities to characters:
The HTML output of the above code is as follows (view source code):
The browser output of the above code is as follows:
Jane & 'Tarzan'
Jane & 'Tarzan'
Example 2
Convert predefined HTML entities to double quotes:
The HTML output of the above code is as follows (view source code):
The browser output of the above code is as follows:
PHP String Reference Manual Other Extensions