Coding practices
Your code is the heart of your application; therefore, you want to write it properly, cleanly, and in an efficient manner. In this section, we will give you some hints to improve your code.
Dealing with strings
One of the standards of the industry is to use the UTF-8 format in all your application levels. If you skip this recommendation, you will be dealing with encoding problems all your project's life. At the moment of writing this book, PHP does not support Unicode at low level, so you need to be careful when dealing with strings, specially with UTF-8. The following recommendations are only if you are working with UTF-8.
In PHP, the basic string operations such as assignation or concatenation don't need anything special in UTF-8; in other situations, you can use the core functions to deal with your strings. Most of the time, these functions have a counterpart (prefixed as mb_*
) to deal with the Unicode. For example, in the PHP core, you can find the substr()
and mb_substr...