
- PHP - Home
- PHP - Roadmap
- PHP - Introduction
- PHP - Installation
- PHP - History
- PHP - Features
- PHP - Syntax
- PHP - Hello World
- PHP - Comments
- PHP - Variables
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ and $$ Variables
- PHP - Constants
- PHP - Magic Constants
- PHP - Data Types
- PHP - Type Casting
- PHP - Type Juggling
- PHP - Strings
- PHP - Boolean
- PHP - Integers
- PHP - Files & I/O
- PHP - Maths Functions
- PHP - Heredoc & Nowdoc
- PHP - Compound Types
- PHP - File Include
- PHP - Date & Time
- PHP - Scalar Type Declarations
- PHP - Return Type Declarations
- PHP - Operators
- PHP - Arithmetic Operators
- PHP - Comparison Operators
- PHP - Logical Operators
- PHP - Assignment Operators
- PHP - String Operators
- PHP - Array Operators
- PHP - Conditional Operators
- PHP - Spread Operator
- PHP - Null Coalescing Operator
- PHP - Spaceship Operator
- PHP Control Statements
- PHP - Decision Making
- PHP - If…Else Statement
- PHP - Switch Statement
- PHP - Loop Types
- PHP - For Loop
- PHP - Foreach Loop
- PHP - While Loop
- PHP - Do…While Loop
- PHP - Break Statement
- PHP - Continue Statement
- PHP Arrays
- PHP - Arrays
- PHP - Indexed Array
- PHP - Associative Array
- PHP - Multidimensional Array
- PHP - Array Functions
- PHP - Constant Arrays
- PHP Functions
- PHP - Functions
- PHP - Function Parameters
- PHP - Call by value
- PHP - Call by Reference
- PHP - Default Arguments
- PHP - Named Arguments
- PHP - Variable Arguments
- PHP - Returning Values
- PHP - Passing Functions
- PHP - Recursive Functions
- PHP - Type Hints
- PHP - Variable Scope
- PHP - Strict Typing
- PHP - Anonymous Functions
- PHP - Arrow Functions
- PHP - Variable Functions
- PHP - Local Variables
- PHP - Global Variables
- PHP Superglobals
- PHP - Superglobals
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP File Handling
- PHP - File Handling
- PHP - Open File
- PHP - Read File
- PHP - Write File
- PHP - File Existence
- PHP - Download File
- PHP - Copy File
- PHP - Append File
- PHP - Delete File
- PHP - Handle CSV File
- PHP - File Permissions
- PHP - Create Directory
- PHP - Listing Files
- Object Oriented PHP
- PHP - Object Oriented Programming
- PHP - Classes and Objects
- PHP - Constructor and Destructor
- PHP - Access Modifiers
- PHP - Inheritance
- PHP - Class Constants
- PHP - Abstract Classes
- PHP - Interfaces
- PHP - Traits
- PHP - Static Methods
- PHP - Static Properties
- PHP - Namespaces
- PHP - Object Iteration
- PHP - Encapsulation
- PHP - Final Keyword
- PHP - Overloading
- PHP - Cloning Objects
- PHP - Anonymous Classes
- PHP Web Development
- PHP - Web Concepts
- PHP - Form Handling
- PHP - Form Validation
- PHP - Form Email/URL
- PHP - Complete Form
- PHP - File Inclusion
- PHP - GET & POST
- PHP - File Uploading
- PHP - Cookies
- PHP - Sessions
- PHP - Session Options
- PHP - Sending Emails
- PHP - Sanitize Input
- PHP - Post-Redirect-Get (PRG)
- PHP - Flash Messages
- PHP AJAX
- PHP - AJAX Introduction
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML
- PHP - XML Introduction
- PHP - Simple XML Parser
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Login Example
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP Advanced
- PHP - MySQL
- PHP.INI File Configuration
- PHP - Array Destructuring
- PHP - Coding Standard
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Try…Catch
- PHP - Bugs Debugging
- PHP - For C Developers
- PHP - For PERL Developers
- PHP - Frameworks
- PHP - Core PHP vs Frame Works
- PHP - Design Patterns
- PHP - Filters
- PHP - JSON
- PHP - Exceptions
- PHP - Special Types
- PHP - Hashing
- PHP - Encryption
- PHP - is_null() Function
- PHP - System Calls
- PHP - HTTP Authentication
- PHP - Swapping Variables
- PHP - Closure::call()
- PHP - Filtered unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - Expectations
- PHP - Use Statement
- PHP - Integer Division
- PHP - Deprecated Features
- PHP - Removed Extensions & SAPIs
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI Process
- PHP - PDO Extension
- PHP - Built-In Functions
PHP String html_entity_decode() Function
The PHP String html_entity_decode() function is used to translate HTML entities into its corresponding characters. It accepts three parameters as argument - string, flags and encoding. This function is the inverse of htmlentities().
Syntax
Below is the syntax of the PHP String html_entity_decode() function −
string html_entity_decode ( string $string, int $flags, string $encoding )
Parameters
Below are the parameters of the html_entity_decode() function −
$string − It is the string to decode.
$flags − It is used to determine how to handle quotes and which document type to utilize.
$encoding − It is an optional parameter that specifies the encoding used when converting characters. If not set, encoding is set to the value of the default_charset configuration parameter.
Available Flags Constants
Here are the list of available flags constants −
Constant Name | Description |
---|---|
ENT_COMPAT | Converts double-quotes and leave single-quotes alone. |
ENT_QUOTES | Converts both double and single quotes. |
ENT_NOQUOTES | Leaves both double and single quotes unconverted. |
ENT_SUBSTITUTE | Used to replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) instead of returning an empty string. |
ENT_HTML401 | Handles code as HTML 4.01. |
ENT_XML1 | Handles code as XML 1. |
ENT_XHTML | Handles code as XHTML. |
ENT_HTML5 | Handles code as HTML 5. |
Supported Character sets
The following character sets are supported in with this function −
Charset | Aliases | Description |
---|---|---|
ISO-8859-1 | ISO8859-1 | Western European, Latin-1. |
ISO-8859-5 | ISO8859-5 | Little used cyrillic charset (Latin/Cyrillic). |
ISO-8859-15 | ISO8859-15 | Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1). |
UTF-8 | ASCII compatible multi-byte 8-bit Unicode. | |
cp866 | ibm866, 866 | DOS-specific Cyrillic charset. |
cp1251 | Windows-1251, win-1251, 1251 | Windows-specific Cyrillic charset. |
cp1252 | Windows-1252, 1252 | Windows specific charset for Western European. |
KOI8-R | koi8-ru, koi8r | Russian. |
BIG5 | 950 | Traditional Chinese, mainly used in Taiwan. |
GB2312 | 936 | Simplified Chinese, national standard character set. |
BIG5-HKSCS | Big5 with Hong Kong extensions, Traditional Chinese. | |
Shift_JIS | SJIS, SJIS-win, cp932, 932 | Japanese. |
EUC-JP | EUCJP, eucJP-win | Japanese. |
MacRoman | Charset that was used by Mac OS. |
Return Value
The html_entity_decode() function returns the decoded string.
PHP Version
First introduced in core PHP 4.3.0, the html_entity_decode() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
This code shows how to use the PHP String html_entity_decode() function to turn special characters in a string into HTML entities and then decode them back to their original form.
<?php $input = "tutorials \"point\" simply <b>easy</b> learning"; $ab = htmlentities($input); $b = html_entity_decode($ab); echo $ab; ?>
Output
Here is the outcome of the following code −
tutorials "point" simply <b>easy</b> learning
Example 2
In the below PHP code we are using the html_entity_decode() function and show how quotes are decoded with the help of flags.
<?php // String with encoded quotes $input = "This is "quoted" text."; // Decode with ENT_QUOTES flag $ds = html_entity_decode($input, ENT_QUOTES); // Output the result echo $ds; ?>
Output
This will generate the below output −
This is "quoted" text.
Example 3
Now the below code decodes entities with a specified encoding with the help of html_entity_decode() function and prints it.
<?php // Encoded string $input = "I love & enjoy coding."; // Decode using ISO-8859-1 encoding $ds = html_entity_decode($htmlString, ENT_NOQUOTES, "UTF-8"); // Output the result echo $ds; ?>
Output
This will create the below output −
I love & enjoy coding.
Example 4
This PHP program is used to decode HTML entities by keeping quotes encoded using the html_entity_decode() function.
<?php // String with quotes $string = "This is "quoted" text."; // Decode with ENT_QUOTES flag $input = html_entity_decode($string, ENT_QUOTES, "UTF-8"); // Output the result echo $input; ?>
Output
Following is the output of the above code −
This is "quoted" text.