PHP htmlspecialchars_decode() Function
The htmlspecialchars_decode()
function converts several predefined HTML entities to characters. The htmlspecialchars_decode() function is the inverse of htmlspecialchars(). The following HTML entities are decoded:
- & Converted as & (ampersand)
- " will be converted as " " (double quotes)
- ' Converted as ` (single quote)
- < Converted as < (less than)
- > Converted as (greater than)
Syntax
htmlspecialchars_decode(string,flags)
Parameter | Description |
---|---|
string | (Required) Specify the string to decode. |
flags | (Optional) Specifies a way to cope with costs and which file kind to use.
|
Example
<?php $str = "The <u>Underline</u> text."; $txt = htmlspecialchars_decode($str); echo $txt; ?>
Output
The Underline text.
Convert HTML entities to characters
Example
<?php $str = "Welcome to the 'World'"."<br>"; echo htmlspecialchars_decode($str, ENT_COMPAT); echo htmlspecialchars_decode($str, ENT_QUOTES); echo htmlspecialchars_decode($str, ENT_NOQUOTES); ?>
HTML Output
<html> <head> </head> <body> Welcome to the 'World' Welcome to the 'World' Welcome to the 'World' </body> </html>
Output
Welcome to the 'World' Welcome to the 'World' Welcome to the 'World'