xxProto Posted December 29, 2009 Share Posted December 29, 2009 Hey everyone, I'm having an issue loading a particular URL with PHP DOMdocument. I'm using this code for a gaming website that is parsing data from an XML file on a separate website. The code works with one XML url, but not the other, so I think it may be something wrong with the server or the XML file itself. This code works and displays correctly: $team = "Clan DiiE"; $teamurl = "http://gamebattles.com/xbox360/call-of-duty-4/team/clan-diie/stats.xml"; $gbturl = "http://gamebattles.com/xbox360/call-of-duty-4/team/clan-diie"; ?> <?php $documentx9 = new DOMDocument(); $documentx9->load( $teamurl ); $sites = $documentx9->getElementsByTagName( "player" ); $i=1; echo "<h1>$team</h1>"; echo "<img src=images/teaminfo.png border=0 /><p> <table border=0> <tr> <td width=150><b><font size=-2 color=#bfd932 >TAG</b></font></td> <td><font size=-2>$clantag</font></td> </tr> <tr> <td width=150><b><font size=-2 color=#bfd932 >GAMES</b></font></td> <td><font size=-2>$activegames</font></td> </tr> <tr> <td width=150><b><font size=-2 color=#bfd932 >ABOUT</b></font></td> <td><font size=-2>$aboutus</font></td> </tr> </table> </p> <br />"; echo "<img src=images/teamroster.png border=0 /><p> <table border=0><tr> <th><font size=-2 color=#008ebf>Gamertag</font></th> <th><font size=-2 color=#008ebf>GB Rank</font></th> <th><font size=-2 color=#008ebf>Title</font></th> <th><font size=-2 color=#008ebf>Date Joined</font></th> <th><font size=-2 color=#008ebf>Profile URL</font></th> </tr>"; foreach( $sites as $site ) { $nameofsites = $site->getElementsByTagName( "name" ); $name = $nameofsites->item(0)->nodeValue; $urls = $site->getElementsByTagName( "url" ); $url = $urls->item(0)->nodeValue; $val1s = $site->getElementsByTagName( "gbRank" ); $val1 = $val1s->item(0)->nodeValue; $val2s = $site->getElementsByTagName( "url" ); $val2 = $val2s->item(0)->nodeValue; $val3s = $site->getElementsByTagName( "memberSince" ); $val3 = $val3s->item(0)->nodeValue; ... This one doesn't.. <?php $team = "Bad Medicine"; $teamurl = "http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine/stats.xml"; $gbturl = "http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine"; ?> <?php $documentx9 = new DOMDocument(); $documentx9->load( $teamurl ); $sites = $documentx9->getElementsByTagName( "player" ); $i=1; echo "<h1>$team</h1>"; echo "<img src=images/teaminfo.png border=0 /><p> <table border=0> <tr> <td width=150><b><font size=-2 color=#bfd932 >TAG</b></font></td> <td><font size=-2>$clantag</font></td> </tr> <tr> <td width=150><b><font size=-2 color=#bfd932 >GAMES</b></font></td> <td><font size=-2>$activegames</font></td> </tr> <tr> <td width=150><b><font size=-2 color=#bfd932 >ABOUT</b></font></td> <td><font size=-2>$aboutus</font></td> </tr> </table> </p> <br />"; echo "<img src=images/teamroster.png border=0 /><p> <table border=0><tr> <th><font size=-2 color=#008ebf>Gamertag</font></th> <th><font size=-2 color=#008ebf>GB Rank</font></th> <th><font size=-2 color=#008ebf>Title</font></th> <th><font size=-2 color=#008ebf>Date Joined</font></th> <th><font size=-2 color=#008ebf>Profile URL</font></th> </tr>"; foreach( $sites as $site ) { $nameofsites = $site->getElementsByTagName( "name" ); $name = $nameofsites->item(0)->nodeValue; $urls = $site->getElementsByTagName( "role" ); $url = $urls->item(0)->nodeValue; $val1s = $site->getElementsByTagName( "gbRank" ); $val1 = $val1s->item(0)->nodeValue; $val2s = $site->getElementsByTagName( "url" ); $val2 = $val2s->item(0)->nodeValue; $val3s = $site->getElementsByTagName( "memberSince" ); $val3 = $val3s->item(0)->nodeValue; Any help would be greatly appreciated. Also, I'm somewhat new with PHP, so any tips on tidying up the code or better approaches to coding with XML are welcomed. Thanks Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/ Share on other sites More sharing options...
xxProto Posted December 30, 2009 Author Share Posted December 30, 2009 Friendly bump. Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/#findComment-985819 Share on other sites More sharing options...
rajivgonsalves Posted December 30, 2009 Share Posted December 30, 2009 add these line on top of your script error_reporting(E_ALL); ini_set('display_errors', '1'); Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/#findComment-985856 Share on other sites More sharing options...
xxProto Posted December 30, 2009 Author Share Posted December 30, 2009 I'm getting this error: Warning: DOMDocument::load() [domdocument.load]: Input is not proper UTF-8, indicate encoding ! Bytes: 0x99 0x52 0x69 0x44 in http://gamebattles.com/xbox360/call-of-duty-modern-warfare-2/team/badmedicine/stats.xml, line: 45 in /home/projec55/public_html/test.php on line 33 Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/#findComment-985860 Share on other sites More sharing options...
rajivgonsalves Posted December 30, 2009 Share Posted December 30, 2009 I actually have not worked with DomDocument if its xml you could use SimpleXml instead. Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/#findComment-985863 Share on other sites More sharing options...
xxProto Posted December 30, 2009 Author Share Posted December 30, 2009 Don't really know how to use simplexml. I'd rather stay with domdocument if possible since the other code is working, I was just hoping someone here would know why the other isnt. Link to comment https://forums.phpfreaks.com/topic/186629-issue-with-php-dom-xml/#findComment-986144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.