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.
This function was inspired from PHP’s built-in function
trim() that removes undesired characters from the start and end of a string, and in case no such characters are provided as second argument to the function, it removes white-space characters from both ends of the string.
Quicksort is practically the fastest way to sort an
array of data. PHP’s
array sorting function
sort() uses QuickSort.
Replacing part of a string with another string is straight forward, but what if you have to replace last occurrence of a character or string with another string.