php domDocument variables
Posted
by
geoffs3310
on Stack Overflow
See other posts from Stack Overflow
or by geoffs3310
Published on 2011-01-11T14:41:45Z
Indexed on
2011/01/11
14:53 UTC
Read the original article
Hit count: 248
Hi, I have the following code at the moment:
$ip = '195.72.186.157';
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML(file_get_contents('http://www.geoffmeierhans.com/services/geo-locator/locate/?ip='.$ip.'&output=xml'));
foreach($xmlDoc->getElementsByTagName('city') as $link) {
$links = array('text' => $link->nodeValue);
}
$city = $links['text'];
echo $city;
Is there a better way to get the city variable? Since there is only one tag called city a loop isn't really needed but I can't get it to work any other way
© Stack Overflow or respective owner