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_COMPATNoYes
ENT_QUOTESYesYes
ENT_NOQUOTESNoNo

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:

Example

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

Result:

&lt;br&gt;An example

Next: PHP htmlspecialchars Function

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.




More 1Keydata Tutorials



PHP addslashes
PHP echo
PHP explode
PHP htmlentities
PHP htmlspecialchars
PHP implode
PHP md5
PHP number_format
PHP print
PHP str_replace
PHP strlen
PHP strpos
PHP strstr
PHP substr
PHP trim

PHP Syntax

PHP Sitemap

PHP Resources