CMYK, RGB and PHP
04 July 2006 - PHP
A month or so ago, we were putting the finishing touches to the Lena White website, which sells OPI nail lacquer, among other things.
Lacquer is all about colour, so we wanted to give shoppers a way to quickly and visually browse all the available colours with colour swatches, rather than the more traditional product shot route. This makes particular sense because all lacquer bottles look pretty much the same, photos of them give a poor impression of the actual colour, and they take up way more screen estate than is helpful to anyone.
Continued » 6 comments » Add a comment »
PHP UTF-8 cheatsheet
03 July 2006 - PHP
When we started building DropSend, we decided to support all languages worldwide from the start. The interface is currently in English only, but the application can send, store, sort and process your data whatever language you want. As a result, we have a good number of customers out east.
To support worldwide languages, you need to use UTF-8 encoding for your web pages, emails and application, rather than ISO 8859-1 or another common western encoding, since these don't support characters used in languages such as Japanese and Chinese.
Happily, UTF-8 is transparent to the core Latin characterset, so you won't need to convert all your data to start using UTF-8. But there are a number of other issues to deal with. In particular, because UTF-8 is a multibyte encoding, meaning one character can be represented by more one or more bytes. This causes trouble for PHP, because the language parses and processes strings based on bytes, not characters, and makes mincemeat multibyte strings - for example, by splitting characters 'in half', bodging up regular expressions, and rendering email unreadable.
There are a number of great articles online about UTF-8 and how it works - Joel Spolski's comes to mind - but very few about how to actually get it working with PHP and iron out all the bugs. So, here to save you the time we put in, is a quick cheatsheet and info about a few common issues.
Continued » 65 comments » Add a comment »
Optimising while() loops in PHP
02 July 2006 - PHP
Following the for() tests, I performed the same tests for while() loops. The speeds were very similar to the for() tests across the board, with just one syntax standing out: the one that doesn't use a comparison operator. It was about 50% faster than all the others:
$i = 1000000 ;
while($i){ $i-- ; }
As with the for() test, this is a count-down loop, which checks the boolean value of $i without a comparison operator for each iteration.
Continued » 2 comments » Add a comment »
Optimising for() loops in PHP
01 July 2006 - PHP
I decided to try a couple of speed tests on for loops in PHP. The results were suprising. The speeds were almost exactly the same, with the exception of one syntax which was about 50% faster than the others, yet is possibly the least used. This is:
for($i=1000000; $i; $i--){}
It is a count-down loop, which checks the boolean value of $i without a comparison operator for each iteration.

