PHP

PHP Convert HTML Entities back to their applicable characters

If you have escaped raw html and want to convert the HTML Entities back to their applicable characters using PHP, then this can be done very easily using just 1 line of code. In this article, I am going to share a very simple way to do it. So read on to find out how to do this.

PHP Convert HTML Entities back to their applicable characters

Ok, if you don’t have a clue as to what escaped html would look like, following is an example:

Escaped HTML:

<?php echo "Hi there!"; ?>

What we need:

<?php echo "Hi there!"; ?>

Solution:

$str = '&lt;?php echo "Hi there!"; ?&gt;';

$new_str = html_entity_decode($str);

echo $new_str;
That’s it!

Do you know of any other ways to Convert HTML Entities back to their applicable characters in PHP? Feel free to suggest by commenting below.

Share your thoughts, comment below now!

*

*