The following PHP code:
<html>
<?php
$name = Secrezy;
$server = Sunstrider;
$raidurl='http://eu.wowarmory.com/character-achievements.xml?r='.$server.'&cn='.$name.'&c=168';
print_r($raidurl); // This is to check if the link is valid. Follow the link printed here and you should find a valid XML page
echo "<br>";
$xmlraid = simplexml_load_file($raidurl);
$achievement = array($xmlraid->xpath("/category/achievement[@id='4602']"));
print_r($achievement);
?>
</html>
Isn't working as I would expect it to. Shouldn't $achievement be populated with this:
<achievement categoryId="168" dateCompleted="2010-03-26T00:01:00+01:00" desc="Complete the 10-player raid achievements listed below." icon="inv_helmet_74" id="4602" points="25" reward="Reward: Bloodbathed Frostbrood Vanquisher" title="Glory of the Icecrown Raider (10 player)">
Instead, I just get an empty array.
Here is the full URL to the page http://eu.wowarmory.com/character-achievements.xml?r=Sunstrider&cn=Secrezy&c=168
Thanks!
Edit: After changing the xpath to /achievements/category/achievement[@id='4602'] which I completely missed, everything works fine. So thanks for that. However, if I implement this into my original code, it still doesn't work as I would expect. I'm sure I'm doing something terribly wrong, so thanks for the help.
<?php
echo "<html>
<head>
<title>ARMORY.</title>
<meta http-equiv='Content-Type' content='text/html' charset=iso-8859-1>
</head>
<body>
<table width='50%' border='1' cellpadding='10' cellspacing='10'>";
ini_set("user_agent", "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8");
$server = "Sunstrider";
$guild = "Operation+Eskimo";
$url='http://eu.wowarmory.com/guild-info.xml?r='.$server.'&gn='.$guild;
$xml = simplexml_load_file($url);
$array = array();
foreach($xml->guildInfo->guild->members->character as $char)
if(strtolower($char['level']) === '80')
{
$array[] = $char['name']."<br />";
}
$i = 0;
while($array[$i] != null)
{
$name = $array[$i];
$raidurl='http://eu.wowarmory.com/character-achievements.xml?r='.$server.'&cn='.$name.'&c=168';
$xmlraid = simplexml_load_file($raidurl);
var_dump($xmlraid);
echo "<br><br>";
$achievement = array($xmlraid->xpath("/achievements/category/achievement[@id='4602']"));
$i++;
}
?>
</body>
</html>
That var_dump of xmlraid only produces this (many many times due to $i):
object(SimpleXMLElement)#3 (2) { ["@attributes"]=> array(2) { ["lang"]=> string(5) "en_us" ["requestUrl"]=> string(27) "/character-achievements.xml" } ["category"]=> object(SimpleXMLElement)#2 (1) { ["category"]=> array(12) { [0]=> object(SimpleXMLElement)#5 (0) { } [1]=> object(SimpleXMLElement)#6 (0) { } [2]=> object(SimpleXMLElement)#7 (0) { } [3]=> object(SimpleXMLElement)#8 (0) { } [4]=> object(SimpleXMLElement)#9 (0) { } [5]=> object(SimpleXMLElement)#10 (0) { } [6]=> object(SimpleXMLElement)#11 (0) { } [7]=> object(SimpleXMLElement)#12 (0) { } [8]=> object(SimpleXMLElement)#13 (0) { } [9]=> object(SimpleXMLElement)#14 (0) { } [10]=> object(SimpleXMLElement)#15 (0) { } [11]=> object(SimpleXMLElement)#16 (0) { } } }
I should add that I'm very new to PHP so my code isn't great.