PHP htmlentities() Function Example

PHP Script:

$str = “A ‘PHPTUTORS’ is <b>Awsome</b>”;
echo htmlentities($str);
echo “< br/ >”;
echo htmlentities($str, ENT_QUOTES);


A ‘PHPTUTORS’ is <b>Awsome</b>< br/ >A ‘PHPTUTORS’ is <b>Awsome</b>


htmlentities() function convert all applicable characters to HTML entities.

In above example the html source will look like


A 'PHPTUTORS' is &lt;b&gt;Awsome&lt;/b&gt;< br/ >A 'PHPTUTORS' is &lt;b&gt;Awsome&lt;/b&gt;


htmlentities() function parameters:

1- string : The input string value.
2- int : Bitmask  for specifying criteria of encodings. [Optional] Default value : [ int $flags = ENT_COMPAT | ENT_HTML401 ]
3- string : Defines encoding used in conversion.  [Optional] Default value : [ string $encoding = ‘UTF-8’ ]
4- bool : When this is false, PHP will not encode existing html entities. [Optional] Default value : [bool $double_encode = true]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s