PHP – How to escape only single quotes?

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.

Continue reading “PHP – How to escape only single quotes?”

Difference between htmlspecialchars_decode and html_entity_decode

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.

Continue reading “Difference between htmlspecialchars_decode and html_entity_decode”

PHP – Convert special character &quot to real quote

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, (&amp; for &, &quot; for “, &lt; for <, &gt for > and so on). So how do you convert it to the normal characters?

Continue reading “PHP – Convert special character &quot to real quote”