Bluwolfe Posted December 10, 2007 Share Posted December 10, 2007 Im currently programming a large site for the game I play: World of Warcraft. Im designing it around security and ease of use, so one of the functions Im providing is player verification. World of Warcraft has a database driven site here: www.wowarmory.com . Blizzard (the developers) have created all their websites using a web server that runs off XML sheets. So every webpage you look at either at www.worldofwarcraft.com or www.wowarmory.com, the source is always beautifully formatted XML sheets, and no HTML or Javascript This is all fine and dandy, I want to be able to read the XML, but sadly I havent accomplished that yet. When my function runs, it pulls in the HTML / Javascript junk. The code is as follows: $handle = fopen("http://www.wowarmory.com/character-sheet.xml?r=".$inServerName."&n=".$inCharacterName."", "rb"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); After this function runs, I basically get the page that is displayed, but rather than receiving the XML formatted page, I get the HTML / Javascript as said above. Ive written my function around this to parse the information, but I would -much rather- have the XML come in and parse that rather than splitting HTML, which to me in the long run would be more reliable than chancing them changing any formatting on their page. I have tried to find another method online to do this but have come across nothing so far. My webserver is also unfortunately only running PHP 4, and not 5 yet. Any help would be greatly appreciated. Thank you! -David Bright http://bluwolfe.net Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 Give this a try Getting the XML thru PHP //Code by Electric@Wow Forums //stick this in a page define("USE_CURL", true); //realm and char name $realm = "Kilrogg"; $name = "Electric" $url = "http://armory.wow-europe.com/character-sheet.xml?r=" . $realm . "&n=" . $name ; $ch = curl_init(); $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); $f = curl_exec($ch); curl_close($ch); your xml is in $f to write it to a file saved under Realm-Name.xml add the following code at the end: $filename = $realm . '-' . 'name' . '.xml'; $somecontent = $f; if (!file_exists($filename)) { fopen($filename, "w"); } else { unlink($filename); fopen($filename, "w"); } // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success"; fclose($handle); } else { echo "The file $filename is not writable"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.