The htmlspecialchars_decode() function converts some predefined HTML entities to characters.
HTML entities that will be decoded are:
The htmlspecialchars_decode() function is the opposite of htmlspecialchars().
PHP htmlspecialchars_decode() Function has the following syntax.
htmlspecialchars_decode(string,flags)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to decode |
flags | Optional. | How to handle quotes and which document type to use. |
The available quote styles are:
PHP htmlspecialchars_decode() Function returns the converted string.
Convert the predefined HTML entities "<" (less than) and ">" (greater than) to characters:
<?php
$str = "java2s.com <b>bold</b> text.";
echo htmlspecialchars_decode($str);
?>
The code above generates the following result.
Convert some predefined HTML entities to characters:
<?php
$str = "Java & '.com'";
echo htmlspecialchars_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "\n";
echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "\n";
echo htmlspecialchars_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
The code above generates the following result.