Just a quick one to share a couple of ways to pad a number with leading zeros… I’ve seen a lot of really poor examples of how to do this so I thought I’d share the two ways I might add leading zeros to a number in PHP.
» Read more: Pad a number with leading zeros in PHP
Archive for the ‘PHP’ category
Pad a number with leading zeros in PHP
August 19th, 2010Validate Australian phone numbers in PHP
January 22nd, 2010Here is a very basic PHP function to validate Australia phone (landline and mobile) numbers.
function validate_phone($number) { $number = preg_replace('/[^\d]/', '', $number); return preg_match('/^(0(2|3|4|7|8))?\d{8}$/', $number) || preg_match('/^1(3|8)00\d{6}$/', $number) || preg_match('/^13\d{4}$/', $number); }
Encoding an object in XML with PHP
November 10th, 2009Why is it so hard to deal with XML in PHP? Why can’t there be a simple ‘xml_encode()’ and ‘xml_decode()’ like there is with JSON??
» Read more: Encoding an object in XML with PHP
Ordinal Suffix PHP Function – Convert integer to ordinal suffix
October 3rd, 2009Here’s a function to get the ordinal suffix of an integer in PHP.
» Read more: Ordinal Suffix PHP Function – Convert integer to ordinal suffix
Joomla 1.5 User Import Script
August 12th, 2009A while ago I wrote a script to bulk import users into a Joomla 1.5 installation… I was surprised (and still am) that there was no good Joomla component to import users from CSV or Excel Spreadsheet. It might be outdated with the newest Joomla builds, but the core might still be a useful starting point.
Validating ABNs and ACNs in PHP
August 10th, 2009Here is a PHP validation class to validate Australian Business Numbers (ABN) and Australian Company Numbers (ACN)
PHP Camel Case functions
August 10th, 2009Here are two PHP functions to convert strings between underscore format and camel case.
E.g. from firstName to first_name and vice versa.
» Read more: PHP Camel Case functions
