Javatpoint Logo
Javatpoint Logo

PHP String htmlspecialchars_decode() Function

The htmlspecialchars_decode() function is an in-built function of PHP, which converts pre-defined HTML entities to characters. It is opposite to the htmlspecialchars() function. HTML entities decoded back to the character will be like-

  • & converts as & (ampersand)
  • " converts as " (double-quote)
  • ' converts as ' (single-quote)
  • &lt; converts as < (less than)
  • &gt; converts as > (greater than)

The htmlspecialchars_decode() function is used to decode the HTML entities into characters, whereas htmlspecialchars() is used to converts the character in HTML entities.

For Example

HTML output = This is some <i> italic </i> text.

Browser output = This is some italic text

Syntax:

Description

Parameters

string (mandatory): string is the first parameter of this function, to which we will decode. This parameter is mandatory.

flags (optional): flag is the second or last parameter of this function that contains one or more flags constants which states how to handle quotes, and which type of document to be used. By default, they are ENT_COMPAT | ENT_HTML401. Available flags constants are given below in the table:

Constant Name Description
ENT_COMPAT ENT_COMPAT is a default parameter, and it only converts double-quotes and leaves single-quotes unconverted.
ENT_QUOTES It converts both single and double-quotes.
ENT_NOQUOTES It does not convert any quotes neither single-quotes nor double-quotes.
ENT_HTML401 It is default parameter and handles code as HTML 4.01.
ENT_XML1 It handles code as XML 1.
ENT_XHTML It handles code as XHTML.
ENT_HTML5 It handles code as HTML 5.

Value returned by htmlspecialchars_decode()

It returns the decoded string.

Changelog

Version Description
5.4.0 The constants ENT_HTML401, ENT_HTML5, ENT_XHTML, and ENT_XML1 were added.

Examples of htmlspecialchars_decode()

Below some example are given of htmlspecialchars_decode() function.

Example 1

Browser Output

Output on browsers for the above program would be like as given below:

PHP String htmlspecialchars_decode() Function

HTML Output

We can see the html source code for the following program in the browser -> More tools -> Developers tools, and press CTRL+P.

PHP String htmlspecialchars_decode() Function

It would look in HTML file like-

Example 2

Browser Output

Output on browsers for the above program would be like as given below:

PHP String htmlspecialchars_decode() Function

HTML Output

The HTML view source program would be like-

PHP String htmlspecialchars_decode() Function

It would be in HTML file like -

Example 3

Browser Output

Output on browsers for the above program would be like as given below:

PHP String htmlspecialchars_decode() Function

HTML Output

The HTML view source program would be like-

PHP String htmlspecialchars_decode() Function

It would be in HTML file like -







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA