Kastang Ramblings of a Geek

10Jan/100

Parsing the WoW Armory – Part 1

Today I pulled a list of every character in We Know from the WoW Armory in 5 lines of code.

< ?PHP
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");
$url='http://www.wowarmory.com/guild-info.xml?r=Eitrigg&gn=We+Know';
$xml = simplexml_load_file($url);
 
foreach($xml->guildInfo->guild->members->character as $char)
        echo $char['name']." - ".$char['level']."<br />";
?>

I never realized how easy is was to pull information from the WoW Armory until now. My method has its obvious flaws, such as the output is in no obvious order. I modified my original script to sort the list in ABC order and added a $server and $guild variable to allow for easy modification. Below is a more refined version, in under 15 lines of code the pulled list is sorted in ABC order and displayed.

< ?PHP
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 = "Eitrigg";
$guild = "We+Know";
 
$url='http://www.wowarmory.com/guild-info.xml?r='.$server.'&gn='.$guild;
$xml = simplexml_load_file($url);
 
$array = array();
 
foreach($xml->guildInfo->guild->members->character as $char)
        $array[] = $char['name']." - ".$char['level']."<br />";
 
sort($array);
 
$i = 0;
while($array[$i] != null) {
    echo $array[$i];
    $i++;
}
 
?>

This script is just a quick and dirty way to accomplish the simple task of pulling names from the WoW Armory. I would recommend against using this in a production environment without some sort of cache/database option implemented.