Doing Random Things in PHP

Suppose you want to display something randomly in a news feed, or pick random elements from an array, or anything random in general. Programming Languages are used to define the way how something must be done. Hence in a technical way, it can’t do things randomly on it’s own. Otherwise it would be an AI (Artificial Intelligence). Doing random things is not done at compiling, but in execution. In case…

Convert Seconds To Hours, Minutes in PHP

Say you’re running a process that runs in the background. It’s better to not let the user lose their patience and tell them when it will finish. But, you have the time remaining in seconds. If we show the user : 567 seconds to complete He/she (user) would have to take a calculator and convert it into minutes or hours. Or if the guy/gal is not a math genius, he…

Convert Bytes To KB, MB, GB in PHP

Say you were displaying the size of a file in PHP. You obviously get the file size in Bytes by using filesize(). You won’t have any idea what the file size is if you read it in Bytes. Bytes is useful for file transmission in a network, but not for human usage. So, it’s better to convert it to human readable form. The circled areas show the converted size from…

Create Table Rows With Alternate Colours in PHP

If you have a lot of rows on a table, users will find it difficult to find which cell is in what row. This is because all the rows have the same colour. If we alternate the colours, then the table will be more understandable. We can alternate colours odd-even wise or by 3 rows etc. It can be easily done in PHP. I will tell you two ways to…

Finding The Value Of Pi

Everyone must have heard of Pi, the irrational number that never ends. It goes by this : 3.14159265... I have been learning about Pi since I was in 8th grade. All the time in school, I was curious about to which Pi extends. Now, I know the extend – Infinity :P. I dedicated my precious Christmas vacation for finding the useless value of Pi. Why ? Curiosity. Simply, the curiosity…

Uploading Images Using AJAX In HTML5

In a post that was published some years ago, I explained how to upload an image using AJAX. But, it is an old trick when HTML5 was not standardized. But, now browsers have evolved and almost every person in the world has an HTML5 supported browser. Besides, the old trick used a JS file which is about 15KB. If we used HTML5 mechanism instead, then you can save about 14KB.…