I've been searching through previous questions for the past hour, so if this exists somewhere else, sorry, but I didn't find it. I'm pretty new to PHP, so forgive me if it's a newbie question. I searched through Google, too.
I'm trying to automate getting the lat/long information from airnav.com for various airports for map updates. I've got an XML file with the airport codes:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AIRPORTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AIRPORT>MXA</AIRPORT>
<AIRPORT>SDM</AIRPORT>
</AIRPORTS>
My PHP is:
<?php
$xml=simplexml_load_file("airports.xml");
foreach($xml->AIRPORT as $arpt)
{
if (preg_match('#[0-9]#', $arpt)){
$arptName = $arpt;}
else{
$arptName = "K" . $arpt;}
$content = file_get_contents("http://www.airnav.com/airport/" . $arptName);
preg_match('#([0-9]{2,2}\.[0-9]{1,})\s\/\s(\-[0-9]{2,2}\.[0-9]{1,})#', $content, $arptmatch);
$lat = $arptmatch[1]; //ERROR HERE (line 27)
$long = $arptmatch[2]; //AND HERE (line 28)
echo "Airport: $arpt\nLat: $lat\nLong: $long\n";
}
?>
This works just fine for the first airport, I get this:
Airport: MXA Lat: 35.8944444 Long: -90.1545833
Which, when I go to the site and check is correct. But for the second airport, I get:
Airport: SDM Lat: Long:
Along with the following errors:
Notice: Undefined offset: 1 in /home/a5308473/public_html/phpStuff/readFromAirNav.html on line 27
Notice: Undefined offset: 2 in /home/a5308473/public_html/phpStuff/readFromAirNav.html on line 28
I can't seem to find any way to fix this. Anyone know what's wrong?