htmlentities() function in PHP
PHP htmlentities() function is used to converts characters to HTML entities. It is an inbuilt function of PHP. The return type of this function is string means it returns the encoded string.
1) $string is a PHP string which characters to be converted into HTML entities by this function. It is required.
2) flags used to specify the quotes and document type used by the function. It is also an optional parameter.
For quotes styles we use:
To avoid invaliding encoding we use:
- For document type
3. characters specify which type of character set is to be used. It is also optional. Possible values are:
4. d_encode used to ensure that the available HTML entities are going to encode or not. It is optional. Although it is a Boolean value so it has two possible values
TRUE: by default it is selected and makes all characters including existing HTML entities encodable.
FALSE: already existing HTML entities will not be converted by the function.
<?php $string = "Chemical formula for water is :'H2O'"; $a=htmlentities($string,ENT_QUOTES); // it will convert single quotes into HTML entities echo $a; ?>
Waiting for your comments