[Snippet] Formatting an IMEI Number in PHP
Formatting an IMEI
number in PHP is reasonably simple. The IMEI (14 decimal digits plus a check digit) or IMEISV (16 digits) includes information on the origin, model, and serial number of the device.
The format of the IMEI is AA-BBBBBB-CCCCCC-D, although it may not always be displayed this way. The IMEISV drops the Luhn check digit in favour of an additional two digits for the Software Version Number (SVN), making the format AA-BBBBBB-CCCCCC-EE
[Snippet] Simplified UK/US Date Conversion
One of my major annoyances in PHP & MySQL world is the different formats when working with dates.
US format: mm-dd-yy, UK format: dd-mm-yy and MySQL's date,datetime, timestamp columns yy-mm-dd. How do you cope with them all? I've been working on a rich UI recently which includes the jQuery date picker, by default thats in US format. UK users expect a date in UK format.
Using WP-Ecommerce Product Downloads without checking out
I've used WP-Ecommerce for a few clients who required an online catalogue, rather than an online store.
One client required a custom product display and wanted to print out the product downloads in the single_product.php file. Apparently its not possible as we're using Product Downloads for something other than what it was designed for.
It was originally designed for electronic products, you add to basket, pay and you can download the product downloads.
Truncate a string to the nearest word
Truncating a string in PHP is easy, substr($start,$finish), but its annoying when it truncates the string mid-word isn't it? Here's how I overcame the issue to truncate the string to the nearest word.
This is a modified function found on the PHP site.
Installing memcached on CentOS/cPanel
memcached a (distributed) memory object caching system vital if your running a HA Linux* setup or a web farm. Or even if you need fast as **** caching for an application.
Consider it extra memory for your server, so you can cache more, for example large arrays, SQL queries and other stuff!
* Actually I've discovered there are memcached extensions for Java, C & .NET. Wow, it just grew up!
Mini WHMCS SagePay Terminal Mod
We have a few customers that phone and pay WHMCS generated invoices over the phone - we now use the SagePay Virtual Terminal.
So I added a link on the Client Summary page with a direct link. Simple and silly I know, but kinda useful.
Smarty Security – Stop .tpl access
WHMCS uses the Smarty template engine. Which means your .tpl files are accessible to anyone that knows the path. Quite easy in WHMCS. Whilst not really a major security risk, its bad practise to all these files to be accessed directly.
Add this code into your .htaccess file.
- <Files ~ "\.tpl$">
- Order allow,deny
- Deny from all
- </Files>
Detecting MIME types in PHP
Detecting MIME types in PHP used to be hellish.
Use the mime_content_type function I hear you say. Returns the MIME content type for a file as determined by using information from the magic.mime file. No, its garbage and thankfully now depreciated.
The PHP documentation suggests we use the Fileinfo PECL extension. I wasted ten minutes of my day trying to make that work. It even comes packaged with PHP 5.3. Still doesn't work.
FreeTDS installation directory is not a FreeTDS installation directory
I recently discovered an error whilst trying to (re)install an older PHP version on a client's server. My client required PHP recompiling with MS SQL support. This in turn requires FreeTDS. Installing FreeTDS is very simple, but PHP wasn't.
CubeCart Tax Classes on Product Page
A client of mine sells a mix of VAT and VAT exempt products via a CubeCart 4 store I setup.
Although CubeCart allows this and calculates the VAT right on the checkout process, it doesn't have any facility to show the customer which tax class the product falls into on the viewProd page.
Annoying.



