PHP code to make XML feed Parse and Display - Please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mdexter
Forum Newbie
Posts: 1
Joined: Thu May 02, 2013 9:23 am

PHP code to make XML feed Parse and Display - Please help

Post by mdexter »

Hello all,

This is my very first post here and I hope someone could help me out on this as it has been a labour intensive time to try and learn all about this coding.
I am trying to learn this coding using PHP and trying to do stuff myself and just through a lot of research.......I have found the holy grail of all XML feeds and this was the one feed that people who look to the main steam rankings for. Ok so I am very excited to share this with you guys and show you what I have done based on how you have educated me so far, please bear with me here:

Ok the XML feed (the holy grail) is the GLOBAL USER RANKINGS, there is only one site using it now:

http://www.aoe2stats.com

They are doing what I a trying to achieve and I think I am 95% there based on what you guys have taught me through the coding, ok so here it is, I hope I still have peoples attention here.

here is the link to the XML FEED:

http://steamcommunity.com/stats/AgeofEm ... 879/?xml=1


Ok, this information I am trying to extract is the following:



http://steamcommunity.com/stats/Ageo...l=1&start=5001
]]>
</nextRequestURL>
<resultCount>5000</resultCount>
<entries>
<entry>
<steamid>76561198032048763</steamid>
<score>689</score>
<rank>1</rank>
<ugcid>-1</ugcid>
<details>
<![CDATA[ ]]>
</details>
</entry>
<entry>
<steamid>76561198011427258</steamid>
<score>632</score>
<rank>2</rank>
<ugcid>-1</ugcid>
<details>
<![CDATA[ ]]>

___________________________________________________


Into a table with 4 columns, with the names on each column:

Steam Name - Score - Rank - Ugcid

Now this is where I am learning also, I need to parse the (steamid)
into the (community id) the steam id is the long number above and the community id is username on steam:

website to show example: steamidfinder.com

ok I have found a script to parse the <steamid>76561198032048763</steamid>

into the person name: Huehnerbein

as an example above, so I have been doing a lot of reaearching and I have found the following:

_____________________________________________________________

Assuming that your input steam_id is $INPUT and your final output array is stored in $OUTPUT, this is the functional for each approach that you could use to convert steam_id to personaname:

Code: Select all

/**
* Convert steam_id to personaname
* @returns STRING The name associated with the given steam_id
* BOOL FALSE if no match was found
*/
function steamID_to_name($INPUT, $OUTPUT)
{
// This gets the relevant part of the API response.
$array = $OUTPUT['response']['players'];

// Using your function to convert `steam_id` to a community ID
$community_id = SteamID2CommunityID($INPUT);

// Linear search
foreach ($array as $array_item)
{
// If a match was found...
if ($community_id == $array_item['steamid'])
// Return the name
return $array_item['personaname'];
}

// If no match was found, return FALSE.
return false;
}
_________________________________________________________________


So the conclusion is the script below, unfortunately is does not work but I have tried to change the neccesary parameters in the script, so the objective is: as what http://www.aoe2stats.com are the only ones who have done it!!

To have the 4 entries in a 4 column table:

Steam Name - Score - Rank - Ugcid

and to have the steamid parse into the community_id or username.

OK THE ACTUAL SCRIPT I HAVE MODIFIED, IT DOES NOT WORK BUT CAN YOU GUYS SHARE WITH ME WHAT MISTAKES I HAVE MADE SO I CAN GET THIS HOLY GRAIL SCRIPT WORKING, I HAVE SPENT HOURS ON THIS:

SCRIPT BELOW:


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Code: Select all

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 
$sFeed = 'http://steamcommunity.com/stats/AgeofEmpiresIIHDEdition/leaderboards/131879/?xml=1' . microtime(true);


/**
* Convert steam_id to personaname
* @returns STRING The name associated with the given steam_id
* BOOL FALSE if no match was found
*/
function steamID_to_name($INPUT, $OUTPUT)
{
// This gets the relevant part of the API response.
$array = $OUTPUT['response']['players'];

// Using your function to convert `steam_id` to a community ID
$community_id = SteamID2CommunityID($INPUT);

// Linear search
foreach ($array as $array_item)
{
// If a match was found...
if ($community_id == $array_item['steamid'])
// Return the name
return $array_item['personaname'];
}

// If no match was found, return FALSE.
return false;
}


$dom = new DOMDocument('1.0', 'utf-8');
$dom->load($sFeed);

$steamid = $dom->getElementsByTagName('steamid');
if ($entry->length > 0)

$score = $dom->getElementsByTagName('score');
if ($entry->length > 0)

$rank = $dom->getElementsByTagName('rank');
if ($entry->length > 0)

$ugcid = $dom->getElementsByTagName('ugcid');
if ($entry->length > 0)

{

?>



<style>


table, td, th
body {
font-family:Verdana, Arial, Helvetica;
font-size: 81%;
margin: 0px;
color: #5c3d0b;
font-weight:bold;
}
{
border:1px solid black;
}
th
{
background-color:e6cb9c;
} 
</style>

<table border="1">
<tr>
<th>NAME</th>
<th>SCORE</th>
<th>RANK</th>
<th>UGCID</th>

</tr>
<?
foreach ($entry AS $entry)
{
$steamid = $entry->getElementsByTagName('steamid')->item(0)->nodeValue;
$score = $entry->getElementsByTagName('score')->item(0)->nodeValue;
$rank = $entry->getElementsByTagName('rank')->item(0)->nodeValue;
$ugcid = $entry->getElementsByTagName('ugcid')->item(0)->nodeValue;


printf("<tr><td>%s</td><td>%s</td></tr>" . PHP_EOL, $name, $percent);
}
print('</table>');

} 
___________________________________________________________________

OK PLEASE PLEASE GUYS WOULD LOVE TO SEE WHAT I HAVE DONE WRONG TO GET THIS SCRIPT WORKING

SO MANY THANKS!!
Post Reply