How to use htmlspecialchars decode in PHP

In this article I will explain how htmlspecialchars_decode() function can be used in PHP.
  • 2286

htmlspecialchars_decode() function in PHP

  • The htmlspecialchars_decode() function is used to convert some predefined HTML entities to characters.
  • The htmlspecialchars_decode() function is the opposite of hrmlspecialchars().
  • some HTML entities that will be decoded are:
    • & becomes & (ampersand)
    • " becomes " (double quote)
    • ' becomes ' (single quote)
    • &lt; becomes < (less than)
    • &gt; becomes > (greater than)

Syntax

htmlspecialchars_decode(string,quotestyle)

Parameter

  • string string is required parameter. it is determine string to be decode.
  • quotestyle quotestyle is optional parameter. Specifies how to decode single and double quotes. some available quote styles are:
    • ENT_COMPAT - This is default value. It's decode only double quotes.
    • ENT_QUOTES - It's decode double and single quotes.
    • ENT_NOQUOTES - It does not decode any quotes.

Example

The following example show to how the htmlspecialchars_decode() function can be used in PHP.

<html>

<body>

<h3 style="color: darkseagreen;">htmlspecialchars_decode() function example in PHP</h3>

    <?php

    $input_string = "&#169 C-sharpcorner.com";

    echo 'After decoding : '.htmlspecialchars_decode($input_string) .'<br>';

    $input_string = "&lt;table&gt;<br/>We are learning php&lt;/td&gt;<br>&lt;/tr&gt;<br>&lt;/table&gt;<br>";

    echo 'After decoding : '.htmlspecialchars_decode($input_string) .'<br>';

    ?>

</body>

</html>

 

Output

htmlspecialchars-decode-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.