View Single Post
Old 03-09-2009, 03:53 AM   #57 (permalink)
Krik
The Contributor
 
Join Date: Feb 2009
Posts: 65
Thanks: 0
Krik is on a distinguished road
Default

Lets brake this down some. Most of the code here is very advanced.

To get what you need you only will be using 2 PHP function libraries. You will need to know about cURL and simple XML. Use php.net for information on any php functions.

Now for the cURL part this is all you need

PHP Code:
$url 'http://www.wowarmory.com/guild-info.xml?r=YOUR+SERVER&n=YOUR+GUILD&p=1';
    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$url);
    
curl_setopt ($chCURLOPT_RETURNTRANSFERtrue);
    
curl_setopt ($chCURLOPT_USERAGENT,  "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
    
    
$rosterxml curl_exec($ch); 
For the $url variable just go to your guilds roster page on the wow armory and copy out the URL.

Now with just that above if you echo the $rosterxml you will see in your browser the XML for your guilds roster.

So now all you need to do is parse the XML and this is where simple XML comes into play.

PHP Code:
$xml = new SimpleXMLElement($rosterxml);

foreach (
$xml->guild->members->children() as $char) {
    echo 
'Name: ' $char['name'] . ' ';
    echo 
'Class: ' $char['class'] . ' ';
    echo 
'Level: ' $char['level'] . ' <br>';

Combining those 2 segments of code will display a quick list of all characters in your guild.

Now for it to be most effective you may want to load that data to a database. And in that case replace the above segement with something like
PHP Code:
    $location "localhost";
    
$username "dbusername"//place your database username here
    
$password "dbpassword"//place your database password here
    
$database "dbname"//place your database's name here
    
$open_db mysql_connect("$location","$username","$password");

    if (!
$open_db) die ('Could not connect MySQL');
    
mysql_select_db($database,$open_db) or die ('Could not open database');

$xml = new SimpleXMLElement($rosterxml);

foreach (
$xml->guild->members->children() as $char) {

$insqry "
INSERT INTO `Roster` ( `record_number`, `Char_Name`, `Char_class`, `Chara_Level` )
VALUES ( '', '" 
$char['name'] . "', '" $char['class'] . "', '" $char['level'] . "' )
"
;

$res_ins mysql_query($insqry) or die(mysql_error());

That is about it for handling the data for your roster. Do note that "name" in $char['name'] is one of the attributes of the <character> node in the XML that you will be parsing. And that any attribute in any <character> node can be retrieved by its attribute name.

So I hope that helps get you going.

PS. I didn't test this so if anyone spots an error please feel free to note it.
Krik is offline  
Reply With Quote