PHP htmlspecialchars_decode() Function
The PHP htmlspecialchars_decode() function is the opposite of htmlspecialchars() function. It converts special HTML entities back to characters. The special HTML entities are:
- & becomes & (Ampersand)
- " becomes " (Double quote) (when ENT_NOQUOTES is not set)
- ' becomes ' (Single quote) (when ENT_QUOTES is set)
- < becomes < (Less than)
- > becomes > (Greater than)
Syntax
htmlspecialchars_decode(string, flags)
Parameters
string |
Required. Specify the string to decode. |
flags |
Optional. Specify how to handle quotes and which document type to use. The available flags constants are:
|
Return Value
Returns the decoded string.
Example:
The example below shows the usage of htmlspecialchars_decode() function.
<?php $str = "<p>this -> "</p>\n"; echo htmlspecialchars_decode($str); //quotes are not converted echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?>
The output of the above code will be:
<p>this -> "</p> <p>this -> "</p>
Example:
Consider one more example to understand htmlspecialchars_decode() function concept.
<?php $str = 'I love "PHP".'; //converts double and single quotes echo htmlspecialchars_decode($str, ENT_QUOTES); ?>
The output of the above code will be:
I love "PHP".
❮ PHP String Reference