Time conversions

12 October 2011

0 Comments

Use following function to convert time into different units e.g. days, months, years, weeks etc It take the value in seconds.

Continue reading...

Shorten a string…

12 October 2011

0 Comments

This simple function returns a shorten string back.

Continue reading...

How to calculate distance between two locations

12 October 2011

0 Comments

A very useful function that can be used to calculate distance between two points using latitude and longitude values. $unit parameter can be passed to get return in miles, kilometers, or nautical miles. How to use: Another function:

Continue reading...

Login into a Joomla website using PHP and CURL

7 September 2011

1 Comment

Following PHP script uses CURL to login into a Joomla 1.5 website to access private pages.

Continue reading...

Creating zip archives in PHP

5 September 2011

0 Comments

PHP comes with a ZipArchive class that lets us create and manipulate .zip files. Creating a Zip file using PHP Following code will create master.zip with files containing master.css, new.css, layout.css Extracting a Zip file using PHP

Continue reading...

How to install mcrypt for PHP in ubuntu

4 September 2011

0 Comments

On my Ubuntu 4.9 with PHP Version 5.3.2-1 I had to install Magento that required myscrypt. To install it, I followed following steps: Sometimes you might get the message “php5-mcrypt is already the newest version“. If so, install with:

Continue reading...

CURLOPT_FOLLOWLOCATION warning message

26 August 2011

0 Comments

While developing a twitter extension I came across following warning message on my Ubuntu development server. After doing some research I found that curl follow location option tells curl to follow a redirect header or not. If the environment in the php.ini is running php in safe mode or an open base dir is set, […]

Continue reading...

A function to generate unique id’s and keys

2 March 2011

0 Comments

Following function will generate id’s/keys without using MD5 or SHA1. PHP function uniqid() to generate Unique ID’s. It will create prefixed unique identifier based on current time in microseconds. This function will return (13 + prefix length) characters long identifier. If ‘lcg’ is true then it will return (prefix length + 23) characters. This function […]

Continue reading...

Arbitrary Number of Arguments in a Function

2 March 2011

0 Comments

How to create a function that accepts any number of arguments? We can use func_get_args. It returns an array comprising a function’s argument list. // note empty argument list function foo() { // func_get_args will return an array of all passed arguments $args = func_get_args(); // Now we can loop through array and find arguments […]

Continue reading...

Finding Domain Name from URL in PHP

21 September 2010

1 Comment

Following are various functions to find domain name in URL using PHP. Regex Method:

Continue reading...