I am currently trying to process a csv file in PHP using preg_match(). An example of the data that I am trying to process is below;
"SN120187","Aldersr Rd Nr Shops","","STHPTN","50 56.4241N","1 25.7587W","1001077307","2010-05-30 15:29:49","10","","SURRSHLT3x32","BSU243L1","iiipiiipiiipiiipiii",
"HA035028","Hursley Road - Leigh House Hospital","","HURSLEY","50 59.6772N","1 23.4412W","","","24","","","","The quick brown fox jumped over the lazy dog The quick brown fox jumped over the lazy dog",
I have a regular expression that I am trying to use on this data (below);
if(preg_match('/^"(?P<code>.+)","(?P<description>.+)","(?P<bay>.*)","(?P<area>.+)","(?P<lat>.+)","(?P<lon>.+)","(?P<build>.*)","(?P<msgTime>.*)","(?P<routes>.*)","(?P<simNo>.*)","(?P<displayType>.*)","(?P<version>.*)","(?P<comments>.*)",$/', $line, $matches)){}
The regular expression works on 95% of the data, however, the data that is not working has the last field in the csv line as non-empty.
I began playing around with the data, (mainly the last field) and found that the following data will not pass through the regex;
"SN120187","Aldersr Rd Nr Shops","","STHPTN","50 54.5512N","1 22.9273W","1001077307","2010-05-30 15:29:49","10","","SURRSHLT3x32","BSU243L1","iiiipiiiipiiiipiiii",
"HA035028","Hursley Road - Leigh House Hospital","","HURSLEY","52 58.3498N","1 26.5421W","","","24","","","","iiiipiiiipiiiipiiiipiiiipiiiipiiiipiiiipiiiipiiiipiiiipii",
However, if you remove one character from the last field from the above data, it will pass. From playing around with it, I have found out that there is no consistant pattern for getting this error; the overal length of the string does not seem to matter (this is shown by adding extra characters to other fields), and also the length of the final field does not matter either.
I have no idea what is going on. Does anyone have any ideas?
I am currently running PHP version 5.3.2, and no error messages are appearing.