Home >>PHP String Functions >PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function

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-

  • & converted to & (ampersand)
  • " converted to " (double-quote)
  • &lt; converted to < (less than)
  • &gt; converted to > (greater than)

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 Values

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 &lt;b>Example&lt;/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>
Output:
This is an Example text.

Here are more examples of htmlspecialchars_decode() function in PHP :

<html>
<body>

<?php
$str = 'I love &quot;PHP&quot;.';
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>
Output:
I love "PHP".

Popular Tutorials