Huhu,
ich hab mir ne kleine Funktion gebastelt, die die Charakterdaten aus dem Armory ausliest. Ist in PHP geschrieben und benötigt SimpleXML und cURL!
Viel Spaß damit
ich hab mir ne kleine Funktion gebastelt, die die Charakterdaten aus dem Armory ausliest. Ist in PHP geschrieben und benötigt SimpleXML und cURL!
Viel Spaß damit
Code:
<?php
function nira_get_charakterinfo($name, $realm, $region) {
/*
* Copyrights by Niranda 2010 niranda.net
*
* AUTHOR:
* Niranda
*
* AUTHOR-DATE:
* 01/07/2010
*
* AUTHOR-PAGE:
* www.Niranda.net
*/
/*
* Get Charakterdata with this functions from wow-armory!
* If $name is a URI, so this function will take this URI to get the data.
* Else you must fill out the other variables correctly.
*
* $name = Charaktername
* $realm = Realm (wow-Server)
* $region = realm-region (There are: "EU" or "US" only!)
*
* RETURNS:
* If all Parameters was right:
* Array with Charakterdatas
*
* Else you get errors:
* 0 = undefined
* 1 = realm not found
* 2 = charakter not found
*/
$url = false;
$read_xml = false;
$return = 0;
if (substr($name, 0, 7) == "http://") {
$url = $name;
$read_xml = true;
} else {
$url = "http://".$region.".wowarmory.com/character-sheet.xml?r=".$realm."&cn=".$name;
$read_xml = true;
}
if ($read_xml === true) { // read xml-data
// set UserAgent
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; rv:1.6) Gecko/20040206 Firefox/1.0.1";
ini_set('user_agent',$useragent);
header('Content-Type: text/html; charset=utf-8');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$check_armory = curl_exec($curl);
curl_close($curl);
// Realm not found
if (strpos($check_armory, "errorhtml") !== false) {
$return = 1;
}
// charakter not found
if (strpos($check_armory, "noCharacter") !== false) {
$return = 2;
}
if ($return == 0) {
$xml = new SimpleXMLElement($check_armory);
$return["name"] = (string)$xml->characterInfo->character['name'];
$return["level"] = (integer)$xml->characterInfo->character['level'];
$return["battlegroup"] = (string)$xml->characterInfo->character['battleGroup'];
$return["faction"] = (string)$xml->characterInfo->character['faction'];
$return["gender"] = (string)$xml->characterInfo->character['gender'];
$return["guildname"] = (string)$xml->characterInfo->character['guildName'];
$return["prefix"] = (string)$xml->characterInfo->character['prefix'];
$return["race"] = (string)$xml->characterInfo->character['race'];
$return["realm"] = (string)$xml->characterInfo->character['realm'];
$return["lastModified"] = (string)$xml->characterInfo->character['lastModified'];
$return["points"] = (integer)$xml->characterInfo->character['points'];
foreach ($return as $key => $value) {
$return[$key] = trim($value);
}
}
}
return $return;
}
?>
Zuletzt bearbeitet von einem Moderator: