PHP htmlspecialchars_decode Function


PHP htmlspecialchars_decode Function : It converts Some HTML entities to its characters equivalent. This function is opposite of htmlspecialchars() function. We are going to explain this example with example and demo.


PHP htmlspecialchars_decode Function Syntax

It Converts the following entities only –

  • & = &(ampersand)
  • " = ” (double quote)
  • ' = ‘ (single quote)
  • < = < (less than)
  • > = > (greater than)

Here is syntax for the function htmlspecialchars_decode

Syntax

htmlspecialchars_decode(string,flags)

Input Parameters

  • string: String to be converted.
  • flag:flag is optional . This is basically used to specify how to handle the quotes and which document type use.

Here are following flags available-

  • ENT_COMPAT : This is default. Converts only Double Quotes
  • ENT_QUOTES : This Converts Both Single and Double Quotes.
  • ENT_NOQUOTES : Converts neither Single nor Double Quotes.
  • ENT_HTML401 : Handle code as HTML 4.01.
  • ENT_XML1 : Handle code as XML 1.
  • ENT_XHTML : Handle code as XHTML.
  • ENT_HTML5 : Handle code as HTML 5.

Return Values

This function returns the converted string.

PHP htmlspecialchars_decode Function Example-

Let’s understand the above function with example and demo –

PHP htmlspecialchars_decode

$string = "<p>Hello World -> "</p>";
echo htmlspecialchars_decode($string);

Try it »

The above example will produce the following output-

Html Output

PHP htmlspecialchars_decode function

Browser Output

PHP htmlspecialchars_decode function


More Example

Let’s have a look over more example and demo here. Here we will explain example with flags.

PHP htmlspecialchars_decode

$string = "<p>Hello &#039; World ->Learn & More Here  "</p>";
echo htmlspecialchars_decode($string, ENT_COMPAT)."<br>";
echo htmlspecialchars_decode($string, ENT_QUOTES)."<br>";
echo htmlspecialchars_decode($string, ENT_NOQUOTES)."<br>";

Try it »

The above example will produce the following output-

Html Output

PHP htmlspecialchars_decode example

Browser Output

Browser Output


Advertisements

Add Comment

📖 Read More