Escaping special characters is a usual business in programming and PHP is not an exception either. There are plenty of escaping functions in PHP and we already mentioned some of them that deal with encoding HTML entities. MySQL is also picky when it comes to special characters and it has its own sets and rules which are usually covered with escaping functions such as addslashes. However, when it comes to storing JSON in the MySQL the approach is a bit different.
There are quite a few similar functions in PHP. Some of them are almost identical like echo and print and some have subtle differences which are not obvious at the first glance. We can put htmlspecialchars_decode and html_entity_decode in this category. There is a lot of confusion between notions of HTML special characters and HTML entities so let’s look into the difference.
In certain situations, you could be messing with HTML special characters in a text. At first glance, you might not even notice these are existing in the text. For example, if you’re looking text in a browser these characters will look just like normal characters. But when you peak into the page source you’ll see very different representations, (& for &, " for “, < for <, > for > and so on). So how do you convert it to the normal characters?