What is the use of the function htmlentities in PHP ?

It helps to convert all applicable characters to HTML entities.

htmlentities()
<?php

htmlentities($str);
// Outputs: A ‘quote’ is &lt ;b&gt ;bold&lt ;/b&gt ;

echo htmlentities($str, ENT_QUOTES);
// Outputs: A & #039 ;quote& #039 ; is &lt ;b&gt ;bold&lt ;/b&gt ; (ENT_QUOTES Will convert both double and single quotes.)
?>

?>