Being an XML you can use DOMDocument
$url = 'http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBO/effectmap.xml';
$xml = file_get_contents($url);
$dom = new DOMDocument;
$dom->loadXML($xml);
$effects = $dom->getElementsByTagName('effect');
foreach ($effects as $effect) {
echo $effect->getAttribute('id'), PHP_EOL;
}
The previous example served only to understand, to get the last 3 ids use array (convert with iterator_to_array
) and use the function array_slice
like this:
$url = 'http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBO/effectmap.xml';
$xml = file_get_contents($url);
$dom = new DOMDocument;
$dom->loadXML($xml);
$effects = iterator_to_array($dom->getElementsByTagName('effect'));//Passa para array
//-3 no segundo parametro pega os 3 ultimos itens
$effects = array_slice($effects, -3);
foreach ($effects as $effect) {
echo $effect->getAttribute('id'), PHP_EOL;
}
Note that file_get_contents
fail you might be due to not enabling external urls access, you can enable this in php.ini (as I explained in this answer link ):
allow_url_fopen=1
Or you can change file_get_contents
by curl, like this:
<?php
$url = 'http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBO/effectmap.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //Transferência binaria
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Força retornar transferência na variável
$xml = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
$dom->loadXML($xml);
$effects = iterator_to_array($dom->getElementsByTagName('effect'));//Passa para array
GZ compressed responses
Sometimes it can happen even if you do not request the header Accept-Encoding
the server still send, this is a problem maybe of bad configuration, in case the link you want to access has this problem, I tried to send the headers, but apparently does not work, so one solution is to use gzdecode
of php, like this:
-
file_get_contents
$url = 'http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBO/effectmap.xml';
$xml = gzdecode(file_get_contents($url));
$dom = new DOMDocument;
$dom->loadXML($xml);
$effects = iterator_to_array($dom->getElementsByTagName('effect'));//Passa para array
-
curl
$url = 'http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBO/effectmap.xml';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //Transferência binaria
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Força retornar transferência na variável
$xml = gzdecode(curl_exec($ch));
curl_close($ch);
$dom = new DOMDocument;
$dom->loadXML($xml);
$effects = iterator_to_array($dom->getElementsByTagName('effect'));//Passa para array