PHP function of the day: htmlentities()

For day 7 of 21 in the “PHP Function of the day” series, I’m going to look at htmlentities().  It takes HTML as an input and converts it to HTML entities.

Let’s take a look.


$html = ‘<h1>Hello!</h1><p>Joe\’s website is at: <a href=””></a></p>’;

echo ‘<br />’;

echo $html;

echo ‘<br />’;

echo htmlentities($html);



See the output


As you can see, this allows you to output HTML to the page without actually rendering it as HTML.

Leave a Reply

Your email address will not be published. Required fields are marked *