Reputation: 23
I am trying to get the airport data from ESNU/UMEA from this data file (Link)
I am trying to match everything after the words ESNU/UMEA and before the next airport listed (trying to match 'four letters' 'slash' 'more then three letters' to match the next airport identifier.
I have done many attempts and still not succeeded, any help is much appreciated.
My code so far:
$url = "http://www.lfv.se/AISInf2.asp?TextFile=idunesaavfr.txt&SubTitle=&T=Sverige%20VFR&Frequency=250";
$raw = file_get_contents($url);
preg_match('/ESNU\/UMEA([\s\S]*?)([A-Z]{4}/[A-Z]{3,})/',$raw,$data,PREG_OFFSET_CAPTURE);
Upvotes: 2
Views: 166
Reputation: 33678
You need to escape the slash because your pattern is enclosed with slashes:
preg_match('/ESNU\\/UMEA(.*?)([A-Z]{4}\\/[A-Z]{3,})/',$raw,$data,PREG_OFFSET_CAPTURE);
I also changed the single backslash to a double backslash, although not stricly necessary because PHP interprets a backslash before unknown characters as a literal backslash.
Furthermore I changed the [\s\S]
to .
which is equivalent.
You could also change the enclosing character to e.g. #
:
preg_match('#ESNU/UMEA(.*?)([A-Z]{4}/[A-Z]{3,})#',$raw,$data,PREG_OFFSET_CAPTURE);
Upvotes: 2