SimpleXML Namespaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamieleshaw
Forum Newbie
Posts: 1
Joined: Wed Feb 17, 2010 2:50 am

SimpleXML Namespaces

Post by jamieleshaw »

Hey, just wondering how I can make this code work.
and yes I have Google'd it.

Code: Select all

 
           $info = simplexml_load_file('http://api.hostip.info/?ip=72.65.29.163');
           $country = $info->{'gml:featureMember'}->{'countryName'};
           $coords = split(",", $info->ipLocation->{'gml:pointProperty'}->{'gml:Point'}->{'gml:coordinates'});
           $lng = $coords[0];
           $lat = $coords[1];
           echo $country;
 
I believe the issue is namespace related, if someone could kindly explain this to me.
Thanks, in advance. :)

--EDIT--
Nevermind, I got it working I simply had to register the namespace, and use xpath.
Post Reply