PHP htmlentities Function

PHP Tutorial > String Functions > htmlentities Function

The htmlentities function in PHP is used to convert characters into corresponding HTML entities where applicable. It is used to encode user input on a website so that users cannot insert harmful HTML codes into a site.

The syntax of the htmlentities function is:

htmlentities ('string', [quote_style], [character_set])

[quote_style] is used to determine whether to convert double quotes and single quotes. Possible values include:

ValueConvert Single QuotesConvert Double Quotes

ENT_COMPAT is the default if quote_style is not specified.

[character_set] is the character set to use.

Let's take a look at the example below:


print htmlentities('<br>An example');


&lt;br&gt;An example

Next: PHP htmlspecialchars Function

Copyright © 2022  All Rights Reserved.  Privacy Policy   About   Contact