PHP htmlspecialchars() Function converts some predefined characters to HTML entities.
A predefined characters are given as below.
- & (ampersand) will be converted to &
- " (double quote) will be converted to "
- ' (single quote) will be converted to '
- < (less than) will be converted to <
- > (greater than) will be converted to >
|string||Required. It is input string.|
Optional. It specifies how to handle quotes, invalid encoding and the used document type.The default is ENT_COMPAT | ENT_HTML401.
Flags for invalid encoding are as below,
Flags for used doctype as below,
Optional. It specifies which character-set to use for string.
Allowed character-set are as below.
Optional.A boolean value that specifies whether to encode existing html entities or not.
Let's see below example to understand php htmlspecialchars() Function in details.
HTML Output for below example in view source as below,
The browser output of the below example as below. Converts ampersand to HTML entities Learn PHP & HTML Converts double quote to HTML entities Online tutorial is available for "php" Converts single quote to HTML entities Online tutorial is available for 'php' Converts less than and greater than to HTML entities <a href='https://www.aryatechno.com/blog.html'>Learn online tutorials</a>