Development

Loading data from a file with PHP

In programming languages common tasks should be easy, and surprisingly often I find my self loading data from some source file into a database. With PHP loading a CSV file into the database - or posting the data to an API - is quite easy. The only trick is to know the functions file_get_contents, split (and possibly list). The routine goes something like this: $fileName = 'rawData.csv'; $content = file_get_contents($fileName); $rows = split("\n", $content ); foreach ($rows as $row) { list($item1, $item2, item3) = split(';', $row); // Do something interesting.

PHP: Removing an item from an array

If you have a php array, but need to nuke an item from it, the unset function is just the tool to do that. When iterating through the array after removing the item, you should be slightly careful. The unset function does remove the item, but it doesn’t “reindex” the array, so you should traverse the array by index-numbers after removing the item. The issue is probably best illustrated by this example:

PHP4 - Game over

Yesterday PHP 4.4.9 was released, and today PHP 4 is officially dead. There wil be no more updates. Don’t worry too much tough. PHP 5 is far superior and there’s absolutely no go reason not to have moved on to PHP 5 long ago. PHP 4 - It was a nice ride and I’m sure you deserve the rest.

Cookie limits in browsers

How many cookies do you neeed and how many does the browsers support? - It seem to come up all to often, so after a bit of digging in search engines, here are (for my own convenience) the findings of what the limits are on cookies in the currently used browsers. The cookie standard (RFC2965) specifies a browser should be able to handle at least 20 cookies per domain, but one thing is a standard - who does the real world look?

Code exit strategy - 3 tips

It seems many developers get stuck in the same systems maintaining the same code for years and years. While it may be a common phenomenon there are a few things you can do as a developer to avoid being trapped in your own code forever. First make things readable. While your brain may be wired to a system of only using single character variable and function names or naming global variables after your cats, no one else will get the system.