Introduction
In this article I describe the PHP string functions html_entity_decode, htmlentities and htmlspecialchars_decode. To learn some other math functions, go to:
- String Functions in PHP: Part1
- String Functions in PHP:Part2
- String Functions in PHP:Part3
- String Functions in PHP:Part4
- String Functions in PHP:Part5
PHP html_entity_decode() Function
The PHP string html_entity_decode function converts all HTML entities to their applicable characters.
Syntax
html_entity_decode(string, quotestyle,character-set) |
Parameter in html_entity_decode Function
The parameters of the html_entity_decode function are:
Parameter |
Description |
string |
It specifies the input string. |
quotestyle |
It specifies how to decode single or double quotes. The possible quote styles are:
- ENT_COMPAT - Default. Decodes only double quotes.
- ENT_QUOTES - Decodes double and single quotes.
- ENT_NOQUOTES - Does not decode any quotes.
- ENT_HTML401 - Handle code as HTML 4.01.
- ENT_XML1 - Handle code as XML1.
|
character-set |
It specifies a string that specifies what character set is used. |
Example
An example of the html_entity_decode function is:
<?php
$str = "We are learning <b>PHP</b> at <a href='http://www.c-sharpcorner.com/1/279/php.aspx'>C-sharpCorner.com</a>";
echo html_entity_decode($str);
?>
Output
PHP htmlentities() Function
The PHP string htmlentities function converts all applicable characters to HTML entities.
Syntax
htmlentities (string, quotestyle,character-set) |
Parameter in htmlentities Function
The parameters of the htmlentities function are:
Parameter |
Description |
string |
It specifies the string to convert. |
quotestyle |
It specifies how to encode single or double quotes. The possible quote styles are:
- ENT_COMPAT - Default. Decodes only double quotes.
- ENT_QUOTES - Decodes double and single quotes.
- ENT_NOQUOTES - Does not decode any quotes.
- ENT_HTML401 - Handle code as HTML 4.01.
- ENT_XML1 - Handle code as XML1.
|
character-set |
It specifies a string that specifies what character set is used. |
Example
An example of the htmlentities function is:
<?php
$str = "MCN Solution at <b>India</b>";
echo "With Out htmlentities Function:". $str."</br>";
echo "When use htmlentities Function:" .htmlentities($str);
?>
Output
PHP htmlspecialchars_decode() Function
The PHP string htmlspecialchars_decode function converts special HTML entities back to characters.
Syntax
htnlspecialchars_decode (string, quotestyle) |
Parameter in htmlspecialchars_decode Function
The parameters of the htmlspecialchars_decode function are:
Parameter |
Description |
string |
It specifies the string to decode. |
quotestyle |
It specifies how to decode single or double quotes. And quote style are
- ENT_COMPAT - Default. Decodes only double quotes.
- ENT_QUOTES - Decodes double and single quotes.
- ENT_NOQUOTES - Does not decode any quotes.
- ENT_HTML401 - Handle code as HTML 4.01.
- ENT_XML1 - Handle code as XML1.
|
Example
An example of the htmlspecialchars_decode function is:
<?php
$input_string = "© C-sharpcorner.com";
echo 'After decoding : '.htmlspecialchars_decode($input_string) .'<br>';
$input_string = "<table>We are learning php</td><br></tr><br></table>";
echo 'After decoding : '.htmlspecialchars_decode($input_string) .'<br>';
?>
Output