Name

htmlspecialchars

Synopsis

string htmlspecialchars(string string[, int style])

Converts characters in string that have special meaning in HTML and returns the resulting string. A subset of all HTML entities covering the most common characters is used to perform the translation. If supplied, style determines the manner in which quotes are translated. The characters translated are:

  • Ampersand (&) becomes &

  • Double quotes (") become "

  • Single quote (') becomes '

  • Less than sign (<) becomes &lt;

  • Greater than sign (>) becomes &gt;

The possible values for style are:

ENT_COMPAT (default)

Converts double quotes but not single quotes

ENT_NOQUOTES

Does not convert either double quotes or single quotes

ENT_QUOTES

Converts both single and double quotes

Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.