How to use htmlspecialchars decode in PHP

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

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)




  • 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.


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



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


    $input_string = "&#169";

    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>';






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


More Articles

© 2020 DotNetHeaven. All rights reserved.