• Register
4,670 points
9 5 1

Html_entity_decode() is a PHP encoding function used to decode or to convert the HTML entities to characters. This function is the opposite function of htmlentities function. This function is used when we are feeling with strings of HTML to convert them into characters.

What is html_entity_decode in php?

This function is used to decode the strings into characters. This function contains three parameters, one is required and the other two are optional.

Structure of html_entity_decode

html_entity_decode(string,flags,character-set)

String:  this parameter is mandatory or required you must specify the string to be decoded.

Flags: This parameter is optional. This parameter is used to specify how to handle quotes and which document type to use.

  • ENT_COMPACT. This is the default flag type. This flag only decodes the double-quotes.

  • ENT_QUOTES- can be used to decode double and single quotes.

  • ENT_NOQOUTES. When this is enabled it will not decode any quotes.

This function has additional flags for doctype. These are as follow ENT_HTML401, ENT_HTML5, ENT_XML1, ENT_XHTML.

Character-set: This parameter specifies which character-set will be used; some examples are UTF-8 the default character set.

Note: If you pass an unrecognized character set it will be replaced by ISO-8859-1 for PHP version before 5.4 and above the version of PHP 5.4 it will be replaced by UTF-8.

This function always returns a value. It returns the decoded string. This function was supported by 4.3.0 +.

Example:  

<?php
$orignal = "PHP is an open source coding language used for <b>WEBSITE<b>!";
$str1 = htmlentities($orignal);//returns the string using htmlenitities
$str2 = html_entity_decode($str1);
echo $str1 "<br>";
echo $str2;
?>

 

4,670 points
9 5 1