PHP Code for XML FEED - Cannot fix requests - Please help!
Results 1 to 3 of 3

Thread: PHP Code for XML FEED - Cannot fix requests - Please help!

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1

    PHP Code for XML FEED - Cannot fix requests - Please help!

    Hi All,

    Very first post here and I have a couple of requests in my question as I have been wracking my brain over this for a very long time, I have used many bits of scripts etc and done tons of research and managed to get my script working this much, please help anyone if you can.

    TRYING TO DO THE FOLLOWING:

    Page is found here BTW:

    http://www.mdexter.com/aoe2hdozclan.com/rankings1.php

    1 . Remove errors, some name entries have errors and an error that comes up with the following:

    Warning: DOMDocument::load() [domdocument.load]: Document is empty in http://steamcommunit...085870722?xml=1, line: 1 in /home/mp/public_html/aoe2hdozclan.com/test.php on line 78

    The line in question is:
    PHP Code:

        
    isset($friendsOf) ? $friendsOf.'/' ''
        
    ).'?xml=1&start=' $start '&end=' $end,
        
    LIBXML_NOBLANKS || LIBXML_NOCDATA
    )) {

        
    $entries $feed->getElementsByTagName('entries');
        if (
    $entries->length>0) { 
    THE LINE IN QUESTION IS THIS: )) {

    which I have a temp fix using:

    // Turn off all error reporting
    error_reporting(0);

    2. Change where avatar is and move it to where rating is, and move rating and rank to the right, and REMOVE UGCID alltogether

    3. Add the avatarMedium from xml details below which adds an avatar image to the avatar column, details of parser found here:

    PHP Code:

    <profile>
    <
    steamID64>76561197963686471</steamID64>
    <
    steamID>-Dare Devil/x/</steamID>
    <
    onlineState>offline</onlineState>
    <
    stateMessage>Last Online2 hrs33 mins ago</stateMessage>
    <
    privacyState>public</privacyState>
    <
    visibilityState>3</visibilityState>
    &
    #8722;
    <avatarIcon>
    http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96.jpg
    </avatarIcon>
    &
    #8722;
    <avatarMedium>
    http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96_medium.jpg
    </avatarMedium>
    &
    #8722;
    <avatarFull>
    http://media.steampowered.com/steamcommunity/public/images/avatars/54/5407c772b001238b61a47762bb57494b0b940e96_full.jpg
    </avatarFull>
    <
    vacBanned>0</vacBanned>
    <
    tradeBanState>None</tradeBanState>
    <
    isLimitedAccount>0</isLimitedAccount>
    <
    customURL>jsmucha</customURL>
    <
    memberSince>January 12004</memberSince>
    <
    steamRating>10</steamRating>
    <
    hoursPlayed2Wk>69.7</hoursPlayed2Wk>
    <
    headline></headline>
    <
    location>DanburyConnecticutUnited States</location>
    <
    realname></realname>
    <
    summary>I like dragons. And zombies.</summary>
    &
    #8722;
    <mostPlayedGames>
    &
    #8722;
    <mostPlayedGame>
    <
    gameName>Age of Empires IIHD Edition</gameName>
    <
    gameLink>http://steamcommunity.com/app/221380</gameLink>
    &#8722;
    <gameIcon>
    http://media.steampowered.com/steamcommunity/public/images/apps/221380/109c74df17f9b67ea47d8f01e3d1ec25278b9f73.jpg
    </gameIcon>
    &
    #8722;
    <gameLogo>
    http://media.steampowered.com/steamcommunity/public/images/apps/221380/37e9da3f1174891fe38f8fb0206acda8b6bfc729.jpg
    </gameLogo>
    &
    #8722;
    <gameLogoSmall>
    http://media.steampowered.com/steamcommunity/public/images/apps/221380/37e9da3f1174891fe38f8fb0206acda8b6bfc729_thumb.jpg
    </gameLogoSmall>
    <
    hoursPlayed>58.1</hoursPlayed>
    <
    hoursOnRecord>110</hoursOnRecord>
    <
    statsName>AgeofEmpiresIIHDEdition</statsName
    The item to parse and create the avatar is: <avatarMedium>

    And that is it for now I have tried so many types of scripts etc but I am coming up short, ok the full script of the page is below:

    PHP Code:

    <?php
       
      
    // Turn off all error reporting
    error_reporting(0);
     
       
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

    /* 
        I limited it to ten because it takes so long to pull every user's
        profile! I suggest setting up some sort
    of caching or daily updates
        if deploying this live.
    */

    $start 1;
    $end 40;
    $friendsOf 133447;
     
    $game 'AgeofEmpiresIIHDEdition';

    $feed = new DOMDocument();
    if (
    $feed->load(
        
    'http://steamcommunity.com/stats/' $game '/leaderboards/'.(
            isset(
    $friendsOf) ? $friendsOf.'/' ''
        
    ).'?xml=1&start=' $start '&end=' $end,
        
    LIBXML_NOBLANKS || LIBXML_NOCDATA
    )) {

        
    $entries $feed->getElementsByTagName('entries');
        if (
    $entries->length>0) {
        
            
    $entries $entries->item(0)->getElementsByTagName('entry');
            if (
    $entries->length>0) {
            
                echo 
    '
                    <table id="leaderBoard">
                        <caption>Age of Empires II HD Leaderboard</caption>
                        <thead>
                            <tr>
                                <th scope="col">Name</th>
                                <th scope="col">Rating</th>
                                <th scope="col">Rank</th>
                                <th scope="col">UGCID</th>
    <th scope="col">Avatar</th>
                            </tr>


    <style>


    table, th
    body {
    font-family:Verdana, Arial, Helvetica;
    font-size: 110%;
    padding-left: 15px;
    margin: 0px;
    color: #825a15;
    font-weight:bold;
    }
    th, td
    {
    border:1px solid black;
    }
    td, th
    {
    background-color:ebcc9b;
    }
    th, td
    {
    padding-right: 15px;
    }
    th
    {
    padding-left: 15px;
    }



    </style>

                        </thead><tbody>'
    ;
                        
                        
                        
                
                foreach (
    $entries as $entry) {

                
                    
    $data $entry->firstChild;
                    
                    
    $user = new DOMDocument;
                    if (
    $user->load(
                        
    'http://steamcommunity.com/profiles/' $data->nodeValue '?xml=1',
                        
    LIBXML_NOBLANKS || LIBXML_NOCDATA
                
    )) {
                        
    $userName $user->getElementsByTagName('steamID')->item(0)->nodeValue;
                        
    // note ALL user data is available here 
                    
    } else $userName '<strong>ERROR</strong>';
                    
                    
                    echo 
    '
                            <tr>
                                <th scope="row">'
    $userName'</th>';
                                
                    while (
    $data $data->nextSibling) echo '
                                <td>'
    $data->nodeValue'</td>';
                                
                    echo 
    '
                            </tr>'
    ;
                            
                } 
    // foreach $entries
                
                
    echo '
                        </tbody>
                    </table>'
    ;
                    
    } else echo 
    '<p>no entries found in entry
    table</p>'
    ;
            
        } else echo 
    '<p>no entries table found</p>';
        
    } else echo 
    '<p>unable to load feed</p>';
    ?>

      <?php
     
    // Do some form processing here
     
    echo '<a href="rankings2.php" font="Arial" style="color: #7d4417">next</a>';

     
    ?>

  2. #2
    Senile Member
    Join Date
    Oct 2002
    Location
    Cheshire, UK
    Posts
    1,660
    PHP Code:
    $xml simplexml_load_file('profile.xml');

    echo 
    $xml->avatarMedium
    Barand

  3. #3
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,884
    1. You can suppress the error message with the '@' operator. You might want to consider reading the file into a string so that you can check it's not empty before attempting to parse it.
    2. 3. Read what you want and figure out what you want to do with it before displaying it.
    Something like
    PHP Code:
    $profiles $document->getElementsByTagName('profile');
    foreach(
    $profiles as $profile)
    {
        
    $name $avatar $etc '';
        foreach(
    $profile->childNodes as $child)
        {
            if(
    $child->nodeType == XML_ELEMENT_NODE)
            {
                switch(
    $child->tagName)
                {
                case 
    'steamID'$name $child->textContent; break;
                case 
    'avatarMedium'$avatar $child->textContent; break;
                
    //...etc
                
    }
            }
        }
        
    // Now write a row of the table.

    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •