31
Dec
Learn how to use PHP htmlentities() function
htmlentities PHP function is used to convert all applicable characters to HTML entities. This function has four parameters named as String, Flags, Encoding and double_encode.
The first parameter gets input as string. Second parameter takes flag to specify how to handle quotes. The default flag is ENT_COMPAT | ENT_HTML401. Remaining parameters are optional.
This function is useful and also use to protect form post data from malicious content. When user submits form data, the form post values passed by htmlentities() function to converts applicable characters into html entities.
<?php $str = “A quote is <b>bold</b>”; echo htmlentities($str); // Outputs: A quote is <b>bold</b> ?>