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”

PHP – What is the difference between echo and print?

PHP can sometimes be confusing where it shouldn’t be. One area of confusion is the issue with duplicate built-in functions. I’m always inclined to think that developers probably had good reason to make duplicates and the most of the times its good assumption.

But is it always true? Let’s see on the example of echo end print functions.

Continue reading “PHP – What is the difference between echo and print?”

PHP – What is the difference between single and double quotes?

Difference between single and double quotes in PHP can be confusing. Moreover, it can lead to unexpected results, so it’s better to get familiar with it so you can avoid bugs.

Let’s dive into the details…

Continue reading “PHP – What is the difference between single and double quotes?”