In this tutorial we will learn How To Convert Special HTML Entities to Characters in PHP. PHP htmlspecialchars_decode() function can be used which is a built-in PHP function made to decode HTML Entities to Characters.
Table of Contents
PHP htmlspecialchars_decode() function
htmlspecialchars_decode() is a built-in PHP function which converts special HTML Entities to characters.
Take a look at the code given below.
<?php
$string = "<b>HowToCodeSchool.com</b>";
echo htmlspecialchars_decode($string);
?>
In above example < and > are two HTML Entities which represent less than < and greater than > characters respectively.
In this code the htmlspecialchars_decode() will convert these entities to characters.
Look at the example given below.
<?php
$string = "'HowToCodeSchool.com'";
echo htmlspecialchars_decode($string);
?>
In above example ' is HTML entity of apostrophe and the htmlspecialchars_decode() will display it as '.