Home » PHP htmlspecialchars_decode() Function

PHP htmlspecialchars_decode() Function

by Online Tutorials Library

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.

You may also like