Instance
The pre-defined HTML entity "<" (less than) and ">" (greater than) converted to characters:
<?php$str = "This is some <b>bold</b> Text. "; echo Htmlspecialchars_decode ($STR);? >
The HTML output of the above code is as follows (see source code):
<! DOCTYPE Html>
The browser output of the above code is as follows:
This is some bold text.
Definition and usage
The Htmlspecialchars_decode () function converts some pre-defined HTML entities to characters.
The HTML entities that will be decoded are:
& Decode into & (and No.)
" Decode into "(double quotes)
' Decode into ' (single quote)
< Decode into < (less than)
> Decode into > (greater than)
The Htmlspecialchars_decode () function is an inverse function of the htmlspecialchars () function.
Grammar
Htmlspecialchars_decode (String,flags)
Parameters |
Describe |
String |
Necessary. Specifies the string to decode. |
flags |
optional. Specifies how quotation marks are handled and which document type is used. Available Quote types:
-
Ent_compat-Default. Decodes only double quotes.
-
Ent_quotes-decodes double and single quotes.
-
Ent_noquotes-do not decode any quotation marks. Additional flags for the document type specified by
:
-
E nt_html401-Default. The code is processed as HTML 4.01.
-
ENT_HTML5-processing code as HTML 5.
-
ENT_XML1-processing code as XML 1.
-
ent_xhtml-as XHTML processing code.
|
technical details
return value: |
returns the converted string. |
php version: |
5.1.0+ |
update log: |
|
More examples
Example 1
Convert some of the predefined HTML entities to characters:
<?php$str = "Jane &" Tarzan ' "; Echo Htmlspecialchars_decode ($str, Ent_compat); default, decode double quotes only echo "<br>"; Echo Htmlspecialchars_decode ($str, ent_quotes);// decode double and single quotes echo "<br>" ; Echo Htmlspecialchars_decode ($str, ent_noquotes); Do not decode any quotes?>
The HTML output of the above code is as follows (see source code):
<! DOCTYPE Html>
The browser output of the above code is as follows:
Jane & ' Tarzan ' Jane & ' Tarzan ' Jane & ' Tarzan '
Example 2
To convert a predefined HTML entity to double quotes:
<?php$str = ' I love " Php". '; Echo Htmlspecialchars_decode ($str, ent_quotes); Decode double and single quotes?>
The HTML output of the above code is as follows (see source code):
<! DOCTYPE html>
The browser output of the above code is as follows:
I Love "PHP".
The Htmlspecialchars_decode () function converts some pre-defined HTML entities to characters.
<?php$str = "This is some <b>bold</b> Text. "; echo Htmlspecialchars_decode ($STR);? >
will be parsed into
<! DOCTYPE Html>
The output of the user's product details.
<p> {sh: $info .intro|htmlspecialchars_decode}</p>