Parsing XML with PHP Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nkinc
    New Member
    • Apr 2007
    • 2

    Parsing XML with PHP Problem

    Hi all,

    I have been trying to parse an XML file using SimpleXMLElemen t in PHP 5, but
    am having difficulty fetching any results.

    I have an airport code in a variable, $mapaddress (for example: KTEB), that I am trying to pass to Geoname.us, which will geocode the airport code and return latitude and longitude coordinates in the form of an XML file. To see the kind of file Geoname returns, click here to see the result for the code "KTEB": http://ws.geonames.org/search?name=KTE B&fcode=AIRP

    I need to parse the lat and lng from the returned xml file and save them as $latitude and $longitude, but I am getting nothing. Here is the code:

    [PHP]$urlair = "http://ws.geonames.org/search?name=$ma paddress&fcode= AIRP";
    $pageair = file_get_conten ts($urlair);
    $xmlair = new SimpleXMLElemen t($pageair);
    $longitude = ($xmlair->geonames->geoname->lng);
    $latitude = ($xmlair->geonames->geoname->lat);
    $code = ($xmlair->geonames->totalResultsCo unt); [/PHP]

    Any suggestions from anybody would be greatly appreciated.

    Nick
  • nkinc
    New Member
    • Apr 2007
    • 2

    #2
    Actually I've been able to narrow my problem down - to put the question most simply now, can anyone provide the code I would use to store the lat and lng data from this xml file into php variables ($latitude, $longitude):

    http://ws.geonames.org/search?name=KTE B&fcode=AIRP

    Thank you again!

    Nick

    Originally posted by nkinc
    Hi all,

    I have been trying to parse an XML file using SimpleXMLElemen t in PHP 5, but
    am having difficulty fetching any results.

    I have an airport code in a variable, $mapaddress (for example: KTEB), that I am trying to pass to Geoname.us, which will geocode the airport code and return latitude and longitude coordinates in the form of an XML file. To see the kind of file Geoname returns, click here to see the result for the code "KTEB": http://ws.geonames.org/search?name=KTE B&fcode=AIRP

    I need to parse the lat and lng from the returned xml file and save them as $latitude and $longitude, but I am getting nothing. Here is the code:

    [PHP]$urlair = "http://ws.geonames.org/search?name=$ma paddress&fcode= AIRP";
    $pageair = file_get_conten ts($urlair);
    $xmlair = new SimpleXMLElemen t($pageair);
    $longitude = ($xmlair->geonames->geoname->lng);
    $latitude = ($xmlair->geonames->geoname->lat);
    $code = ($xmlair->geonames->totalResultsCo unt); [/PHP]

    Any suggestions from anybody would be greatly appreciated.

    Nick

    Comment

    Working...