Use the following function to find the percentage value of one number to another. If the $total parameter is zero then zero is returned as this would otherwise result in a division by zero error.
Use the following function to work out the number of days between today and a date in the future. The function takes three parameters of the day, month and year of the date in question.
To use this function just give it a date, here are some examples.
Rot13 (which stands for "rotate by 13 places") is a name given to a simple encoding algorithm (or substitution cipher) that is used to mask text. It works by making each letter 13 spaces further along in the alphabet so that a becomes n and b becomes o. For the letter n the alphabet starts again from the beginning.
If you allow users to upload data to your site you might have a situation where a data directory might be full of temporary files. In the long term you will want to get rid of these files as they have served their purpose and are no longer needed.
Providing a text box for users to type information in is very common, but usually people want to include line breaks and links with the text and they expect the site to lay it out just as they had intended it. The following function will turn any ASCII text string into the approximate HTML equivalent.
Sending multiple arguments to a function can be done using a parameter string. This is just like a URL that has data encoded into it. For example, if you wanted to send two parameters (called parameter1 and parameter2) to a function then you would use the following string.
To use this in the function you create the function as normal with a single parameter. This single parameter is the string that will contain all of your arguments.
Garbage collection is a term for a maintenance function in a class or script that you don't want to run every time the script is run. The main function of the script is to clean up anything that the script has used previously, but is now not important in the general running of the system and can be removed with no ill effects. However, it is important that the garbage collection is not run every time the script is run as it may have a detrimental effect on the speed of the system.
Following on from the previous post about the PHP filter functions there are two more filter functions that require some extra explanation. These functions are filter_var_array() and filter_input_array().
They work in much the same way as filter_var() and filter_input() but they accept an array as the input. This enables you to sanitize or validate many different variables at the same time.
Working out the average of a bunch of values is quite a common task, but rather than looping through the array, adding together values as you go and the using the count() function to find out the average at the end.
Sometimes you will want to get a random value form an array in a biased random way, that is, you will want certain values to be returned more than others. Here is a function that will generate a single key from an array, with a greater change of a higher value being retrieved.