1

I'll just post the whole thing since it would be a bit confusing otherwise:

<?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'>"; $server = "Sunstrider"; $guild = "Mist"; $url='http://eu.wowarmory.com/guild-info.xml?r='.$server.'&gn='.$guild.'&p=1'; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); $xml = curl_exec($ch); $rosterxml = new SimpleXMLElement($xml); curl_close($ch); $array = array(); foreach($rosterxml->guildInfo->guild->members->character as $char) if(strtolower($char['level']) === '80') { $array[] = $char['name']."<br />"; } echo " <tr> <td valign='middle'>Name</td> <td valign='middle'>TEST</td> </tr>"; $i = 0; while($array[$i] != null) { $name = $array[$i]; $raidurl='http://eu.wowarmory.com/character-achievements.xml?r='.$server.'&cn='.$name.'&c=168'; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $raidurl); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); $xml2 = curl_exec($ch); $achievementxml = new SimpleXMLElement($xml2); curl_close($ch); var_dump($achievement); echo "<tr> <td>$array[$i]</td> <td></td> </tr>"; $i++; } ?> </body> </html> 

That var_dump of $achievement just produces NULL over and over again (obviously due to the loop) instead of any information about the array. Doing a var_dump of $rosterxml produces the expected effect though, so cURL seems to work fine outside of the while loop.

5
  • Have you tested the URL it is attempting to access inside the loop? Commented Jul 21, 2010 at 18:46
  • See here how to handle curl errors : fr.php.net/manual/en/function.curl-error.php Commented Jul 21, 2010 at 18:47
  • I still like the libxml_set_streams_context() anti-user-agent-sniffing solution better :) Commented Jul 21, 2010 at 18:53
  • @Wrikken, you're probably right! Commented Jul 21, 2010 at 18:56
  • You don't need to constantly instantiate a new curl for every loop iteration. Do that outside the loop along with the useragent/returntransfer options, and just change the URL inside the loop. Curl objects can be reused for multiple requests. As well, never assume the curl exec succeeded as you are. Always check if it returns FALSE (ie: failed) Commented Jul 22, 2010 at 3:09

1 Answer 1

5

That is because your variable is called $achievementxml and not $achievement.

I would advise you to code with error_reporting=E_ALL so you can catch errors like this. Undefined variables will result in an E_NOTICE level error message.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, when developing, you can even use E_ALL | E_STRICT to get maximum verbosity.
Aha, it would appear that I am an idiot. Thanks, and thanks for the advice. I'm quite new to PHP as you might be able to tell, and I'm probably not helping matters by keeping my code completely devoid of comments, but there you have it!
Or the shortcut: -1 (which would set all bits), so possibly even new thought op E_* constants in future, until we get a E_REALLY_ALL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.