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
thus:
$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 may be due to not enabled access to external urls, you can enable this in php.ini (as explained in this reply /a/72746/3635):
allow_url_fopen=1
Or you can trade file_get_contents
by Curl, thus:
<?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
Compressed responses GZ
Sometimes it can occur even if you do not request the header Accept-Encoding
the server still send, this is a problem perhaps of bad configuration, in case the link you want to access this with this problem, I tried to send the headers, but apparently does not work, so one solution is to use the gzdecode
php, so:
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
Could use the
str_split()
to cut the string intoid="
After I cut you into aforeach
takes only the first three letters of each item.– Leonardo
What the whole code would look like?
– Rafa
Is that code really a string? I’ll post the answer.
– Leonardo
did not understand your question, this code I showed is just an example of the IDS to take from the link: http://hebbohotel.com.br/swf/gordon/RELEASE-HEBBBO/effectmap.xml
– Rafa