这行得通;
$s = simplexml_load_file("http://apps.db.ripe.net/whois/lookup/ripe/inetnum/79.6.54.99.xml");
foreach ($s->objects->object->attributes->attribute as $attr) {
$attrs = $attr->attributes();
if ((string) $attrs->name == "country") {
$country = (string) $attrs->value;
break;
}
}
print $country; // IT
但也有一个选项,如果它适合你;
$s = file_get_contents("http://apps.db.ripe.net/whois/lookup/ripe/inetnum/79.6.54.99.xml");
preg_match_all('~<attribute\s+name="country"\s+value="(.*?)".*?/>~i', $s, $m);
print_r($m);
出去;
大批
(
[0] => 数组
(
[0] => <attribute name="country" value="IT"/>
)
[1] => 数组
(
[0] => IT
)
)