Home >>PHP String Functions >PHP htmlspecialchars_decode() Function
PHP htmlspecialchars_decode() function is used to convert predefined HTML entities to characters. Htmlspecialchars_decode() function is an in-built function of PHP. PHP htmlspecialchars_decode() function is opposite of the PHP htmlspecialchars() function. HTML entities decoded back to the character using this htmlspecialchars-decode() will be like-
PHP htmlspecialchars_decode() function is used to decode the HTML entities into characters but PHP htmlspecialchars() function is used to convert the character into HTML entities.
Syntax:-
htmlspecialchars_decode($string,$flags);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter specifies the string to be decoded |
flags | This is an optional parameter. This parameter specifies how to handle quotes and which document type to be used in the function. |
Here is an example of htmlspecialchars_decode() function in PHP :
<html> <body> <?php $str = "This is an <b>Example</b> text."; echo htmlspecialchars_decode($str); ?> </body> </html>
The HTML view of the above code will be:
<html> <body> This is some <b>Example</b> text. </body> </html>
Here are more examples of htmlspecialchars_decode() function in PHP :
<html> <body> <?php $str = 'I love "PHP".'; echo htmlspecialchars_decode($str, ENT_QUOTES); // Converts double and single quotes ?> </body> </html>
The HTML view of the above code will be:
<html> <body> I love "PHP". </body> </html>