If like me you work in PHP, then you will need a caller function to run the perl script. Download this and save it as caller.php.
A brief look at the code will see that whitespace is removed wherever it occours, and the grid reference is trimmed to 6-figures. Note that 6, 8 or 10 figures are accepted as input, but the results will only be as precise as a 6-figure grid reference. A regular expression checks that we then have two letters followed by six figures.
Note that the letters are not compulsory, and in this incarnation of the script ‘SE’ are the default, for no other reason than they cover most of West Yorkshire, where I live at the time of writing.
The script then calls the perl using shell_exec. Check that OSGBPATH will be set to the location of the perl script and if required edit the relevant line near the start of caller.php
Two functions are provided to output Javascript to create Google Map objects - the first just creates a location object, while the second creates a marker on an already existing map. This map is referenced using the Javascript variable map which must be already created using new Gmap2 and centred using the setCenter method. Note that two variables are set; marker and markerlocation. markerlocation is a Google Map location object, and can be used (for example) to pan the map to this location. See the Google Map API for more info on what you can do with Google Maps.
Errors result in null or empty strings being returned.