PHP Logo

PHP fgetcsv() Gotcha

19th May 2012 - 2 minutes read time

I quite often find myself with the need to pull the data from a CSV file into a system. This might be to fill out essential data like postcodes or to update a site with new content. What system I happen to be using dictates how I pull in the CSV file, but writing a quick parser is quite easy in PHP via the use of the fgetcsv() function.

Unfortunately, when using this function it is quite easy to miss something quite important and creates a quite useless piece of code. Take the following example. It appears to be fine at first glance, but the output of the code is always to run once and stop.

An Introduction To OpenLayers

19th May 2012 - 6 minutes read time

OpenLayers is a powerful and open source mapping solution written in JavaScript that can display mutliple different mapping services on web pages. What this means is that you can create a mapping tool using Google Maps and swap it to use Bing Maps at a later date without having to totally rewrite your code. OpenLayers works by building up a series of layers that fit together to form mapping, tools, information and even utilities like KML parsing and AJAX. Vectors and markers can also be used to add layers of information onto the map.

A map in OpenLayers (and most other mapping services) is essentially a set of images called "tiles". When you load a map all you are doing is loading in a bunch of map tiles which OpenLayers then places in the correct place. As you move around a map or change the zoom factor then other map tiles are loaded in to build the new view of the map.

Drupal Logo

EU Cookie Law Talk

15th May 2012 - 2 minutes read time

A couple of months ago I gave a talk at the North West Drupal User Group in Manchester where I talked about the EU Cookie Law and about cookies in PHP and Drupal. The EU law has been in practice in the EU for the last year and is due to be implemented in the UK on May 26th 2012.

People have been asking me to provide them with the slides so I thought I would create a quick blog post and put them on #! code.

Cookies and the EU Law.

Drupal Logo

Getting Started With Drush Make

12th May 2012 - 13 minutes read time

Drush is a command line tool that allows interaction with a Drupal site. The tool itself is incredibily useful and provides mechanisms to download modules, backup databases and most other things that can be done with Drupal. Drush Make was a plugin for Drush which has now become part of the Drush core and allows Drupal sites to be created via a make file. What Drush Make does is to use the make file to download the modules, themes and libraries needed for a Drupal site ready for the site to be installed. This means you can give this make file to another developer who can then build their own Drupal site.

JQuery Logo

Easy QR Code Generation With Google Charts API

26th April 2012 - 4 minutes read time

When I found about the ability to create QR codes using the Google Charts API I decided to sit down and create a little tool that would generate QR codes for me. I've had this tool for a while and I recently noticed that the QR code mechanism has become deprecated. The API will still work for a couple of years so I thought it was worth posting this. Creating a static QR code using Google Charts is quite easy, all you need to do is create an image. For instance, to create a QR code for the #! code address I would do the following.

<img src="" />

Which creates the following image.

Python Logo

Multi-line Comments In Python

13th April 2012 - 2 minutes read time

Python doesn't officially support multi-line comments, but there is a way of implementing the same functionality using an existing language construct. Single line comments in Python are written like this:

# This is a single line comment.

Multi-line comments are not officially supported in Python. That said, you can create the same effect in Python by using a multi-line string. Unless it is part of a docstring at the start of a class, function or module then it parsed into a string variable, but nothing is done with it.

Python Logo

Stopping Code Execution In Python

13th April 2012 - 2 minutes read time

I am currently in the process of learning Python, so I thought I would start a series of mini blog posts detailing different things that I have found useful whilst learning how to use the language.

To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program running. It is the most reliable, cross-platform way of stopping code execution. Here is a simple example.

Drupal Logo

Drupal7: Tip On Adding Code To Drupal Forms

7th April 2012 - 2 minutes read time

There are various different forms and modules in Drupal that allow for PHP code to be embedded into them. I have even talked about adding PHP code to forms in a previous post. These form elements can have their uses, modules like Views allow for PHP code to be run when collecting arguments which can allow for some advanced funcationality.

However, it can lead to problems. The code in the form is essentially outside of source control which means that anyone can mess about with the code and there is no way to revert changes or get back the code if the form save action failed for whatever reason.

Phing Logo

Using Phing To Create Apache Virtual Hosts

6th April 2012 - 10 minutes read time

Phing is an awesome tool for automating things and I use it more and more for automating all kinds of different tasks. One of the tasks that I don't tend to do all that much is setting up a new local virtual host for Apache on my development machines. I know how to do it, but there is always something I forget to do, or a convention that I don't follow which means that I have to repeat myself at a later date to fix something I have missed.

So to make my life a little easier I decided to create a Phing build file to automatically create a virtual host and the everything associated with it in one go. Essentially, I would need to do the following tasks:

Phing Logo

Adding A Context Menu Item For Phing On Windows

21st March 2012 - 2 minutes read time

To make things a bit quicker when using Phing on Windows use the following registry entry to create a right click option that integrates with Phing.