I’m trying to get the <countryAbbrev> using SimpleXML from http://api.hostip.info/?ip=188.222.185.221 There are namespaces so I’m using children() but I just can’t seem to get deep enough. I know there are workarounds but I want to try to do it properly so I know where I’m going wrong.
[COLOR="Red"]<-- You are here ...[/COLOR]
Array
(
[0] => SimpleXMLElement Object
(
[COLOR="Red"]<-- ... so here is $result[0] ...[/COLOR]
[Hostip] => SimpleXMLElement Object
(
[COLOR="Red"]<-- ... here is $result[0]['Hostip'] ...[/COLOR]
[ip] => 188.222.185.221
[countryName] => UNITED KINGDOM
[countryAbbrev] => UK [COLOR="Red"]<-- ... and that is $result[0]['Hostip']['CountryAbbrev'][/COLOR]
[comment] => SimpleXMLElement Object
(
)
[ipLocation] => SimpleXMLElement Object
(
)
)
)
)
Yikes. At index 0 there actually is a SimpleXMLElement. I missed that.
It should be:
[COLOR="Red"]<-- You are here ...[/COLOR]
Array
(
[0] => SimpleXMLElement Object
(
[COLOR="Red"]<-- ... so here is $result[0] ...[/COLOR]
[Hostip] => SimpleXMLElement Object
(
[COLOR="Red"]<-- ... here is $result[0]->Hostip ...[/COLOR]
[ip] => 188.222.185.221
[countryName] => UNITED KINGDOM
[countryAbbrev] => UK [COLOR="Red"]<-- ... and that is $result[0]->Hostip->countryAbbrev[/COLOR]
[comment] => SimpleXMLElement Object
(
)
[ipLocation] => SimpleXMLElement Object
(
)
)
)
)