replaced substr with php shim

Signed-off-by: Nick Brook <nick@rmpenterprise.co.uk>
Fix for last commit

Signed-off-by: Nick Brook <nick@rmpenterprise.co.uk>
reformat

Signed-off-by: Nick Brook <nick@rmpenterprise.co.uk>
Fixes ported from PHP

Signed-off-by: Nick Brook <nick.brook@ratemyplacement.co.uk>