Alun Rowe

ramblings about cars, tech, web development and more. BOTB Winner in 2010

Category: php

Validate MRZ passport numbers with Regex and PHP

Recently I needed to validate MRZ passport numbers using the Machine Readable Passport Zone (MRZ) numbers and PHP.

My weapon of choice is PHP but I’ve included the raw REGEX too to help others.  I used High Programmer to understand the parts of the code and then REGEXR to help test my REGEX codes.


MRZ line 1: [A-Z0-9<]{2}[A-Z<]{3}[A-Z0-9<]{39}

$regex = ‘^[A-Z0-9<]{2}[A-Z<]{3}[A-Z0-9<]{39}$^’;

$result = preg_match($regex, $value);

returns TRUE or FALSE


MRZ Line 2: [A-Z0-9<]{9}[0-9]{1}[A-Z<]{3}[0-9]{6}[0-9]{1}[FM<]{1}[0-9]{6}[0-9]{1}[A-Z0-9<]{14}[0-9]{1}[0-9]{1}

$regex = ‘^[A-Z0-9<]{9}[0-9]{1}[A-Z<]{3}[0-9]{6}[0-9]{1}[FM<]{1}[0-9]{6}[0-9]{1}[A-Z0-9<]{14}[0-9]{1}[0-9]{1}$^’;

$result = preg_match($regex, $value);

returns TRUE or FALSE


I hope this is useful to you!

Connect SequelPro to Homestead Vagrant Mysql database

Although you can run multiple apps per vagrant box I’ve always been happier running Homestead in the Per Project mode.  It keeps things neat and tidy for me.  I’ve also found with more complex setups that Laravel Valet doesn’t always work as intended.

Using the default passwords the step as are as below.  If you start changing your defaults this may not work for you…

Ok, first step is to open SequelPro and create a new connection by clicking the small plus sign in the bottom left.

Add a connection to Sequel Pro

Next up click the SSH button in the connection window.

Choose SSH connection type in SequelPro

Now simply fill in the following details:


MySQL Host
Leave empty (3306 as default)
SSH Host (Or whatever you set yours too in your Homestead.yaml file)
SSH User
SSH Password
SSH Port
Leave empty
Connect using SSL checkbox
Leave empty

Now click Test Connection.

You will be asked if you want to trust the SSH server.  Choose Yes and you are good to go!

Posting a form in WordPress sends you to a 404 page

Recently I had to write an integration to a third party iframe embedded application. It really wasn’t pretty and I’ll write up the results soon for that BUT the big thing I faced was an issue where by *posting a form to a WordPress page resulted in a 404 error*.

I tried all sorts of things to fix it and couldn’t even get a result out of adding

echo '<pre>';
echo print_r($_POST, 1);
echo '</pre>';

nothing. Not a damned thing!

So I tried setting up a simple form with just a field called field1 and it worked fine!

So, after a bit of searching forums and blog posts I finally found out that there are a bunch of reserved field names that you MUST NOT USE under any circumstances when trying to post a form to a WordPress page.

So, simply change the form field names to ones that aren’t on the list and all will be fine.

The most commonly used by me reserved field names are:

  • day
  • debug
  • error
  • m
  • name
  • year

and a full list can be found here:

Hope that helps!

Turn a SimpleXML object into a PHP array

Nice simple quick trick but makes dealing with SimpleXML so much easier!

Basically grab your XML into a variable. JSON Encode it then JSON decode it and Ta da!


bc. $array = json_decode(json_encode((array)simplexml_load_string($xml)),1);


Excel/VBA equivalent of the PHP Implode function

On a recent data import between Xero and OnePageCRM I needed to turn multiple column address into an address list into a single line.  For this I needed the PHP implode function so I wrote one for Excel.

The data was structured like this:

And I needed this:

My immediate faction was to use the implode function that I use in PHP everyday but it appears to be missing in Excel so I quickly wrote one.

To add this code you need to do the following:

  1. Open your work book
  2. Press ALT + F11 and the code window should appear
  3. Right click on VBA project and choose INSERT then MODULE
  4. Copy paste the following code:


Function IMPLODE(Rng As Range, Sep As String)
Dim TEMP As String
For Each Cell In Rng
If Cell.Value = "" Then
TEMP = TEMP & Cell.Value & Sep
End If
Next Cell
TEMP = Left(TEMP, Len(TEMP) - Len(Sep))
End Function

Now in your worksheet go to the cell you want the combined field to be added to and type

=IMPLODE(A1:A3, ",");

and Excel will magically merge the 3 columns A1, A2, A3 together and separate them using the separator you defined.


Codeigniter Beginners Tutorial Article

Over the Xmas break I was lucky enough to be asked to write an article for the “12 Devs Of Xmas”: website. Despite my advancing years this was the first time I’d been asked to write about web development in a technical manner so it was a bit of a learning curve for me.

The article is a very simple introduction to CodeIgniter but will hopefully get people far enough into the framework to start playing for themselves. Enjoy!

“Get to grips with CodeIgniter”:

Hopefullly it has been useful to many of you, and if not then let me know how I can improve for the future as I intend to keep writing now as I thoroughly enjoyed the experience.

Powered by WordPress & Theme by Anders Norén