In this post I will demonstrate the working of
utf8_* family of functions that belong to Portable UTF-8 Library.
Portable UTF-8 library is a Unicode aware alternative to PHP’s native string handling API. It is written in PHP and can work without
iconv, UTF-8 support in PCRE, or any other library. The benefit of Portable UTF-8 is that it is very light-weight, fast, easy to use, easy to bundle, and it always works (no dependencies).
When the php.ini directive
auto_globals_jit is enabled,
$_ENV super global arrays are created at the time they are first used in the script, rather than being initialized at the start of script. The benefit of this directive is that these super global arrays are not created at all if not used within a script, resulting in a little performance gain.
As of PHP 5.4, the
register_globals feature has been removed from php. If you still need the feature, this post is for you.
Since the introduction of
register_globals feature in PHP, there was a lot of discussion around the web criticizing this feature as a security risk. There established a perception that all websites on servers having
register_globals enabled are insecure and vulnerable to hacking/injection. Consequently, the feature went to
Off in PHP 4.2, deprecated in PHP 5.3 and completely removed in PHP 5.4. Even before all this, many web hosts disabled this feature. This caused problems to those not-by-profession PHP coders who rely on ease of use of PHP language to code their business or personal website.
PHP’s random number functions generate integers with variable number of digits. Also, the maximum size of the random number generated that way is
PHP_INT_MAX. You can remove these two limitations using the function below.
Random numbers functions
mt_rand are easy to use and pretty fast. Numbers produced by these functions range from
PHP_INT_MAX unless you specify your own range. In case you use a custom range, it generates a random number within that range, but – it gets slower.
While we already have
rtrim() in php, here is how we can implement the same feature. These are listed here just for understanding the process. In practice, you are recommended to use the built-in functions for performance and consistency reasons.
ASCII is one of the earliest character encoding scheme providing a way of encoding control characters, commonly used symbols, alphabets and digits. Many modern character encoding schemes extend the character set used by ASCII by providing additional characters so as to not only maintain backward compatibility but also achieve the benefits of encoding more international characters.
Often it is required to convert a number or integer to English Words for printing on invoices or for displaying final bill on checkout pages of online shopping carts.