Jump to content

PHP Coding for XML Feed to Parse and work


mdexter

Recommended Posts

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:

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/AgeofEmpiresIIHDEdition/leaderboards/131879/?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:


/**

* 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 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:


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


<?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!!

Link to comment
Share on other sites

Here you go.

 

Change the $show_result_amount value to how many results you want.

 

<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>
<?php
$xml = simplexml_load_file('http://steamcommunity.com/stats/AgeofEmpiresIIHDEdition/leaderboards/131879/?xml=1');
//print_r($xml);

$entries = $xml->entries->entry;
$str = "http://steamcommunity.com/profiles/{{STEAMID64}}/?xml=1";
$count = 1;
$show_result_amount = 10;

echo "<table border='1' bordercolor='#FFCC00' style='background-color:#e6cb9c' width='100%' cellpadding='3'> <tr>
<th colspan='4'> <h3><br>Steam Top Players</h3> </th> </tr> <th>Player Name</th> <th>Score</th> <th>Rank</th> <th>Ugcid</th>";

foreach( $entries as $key => $entry ) {
$userURL = str_replace( "{{STEAMID64}}", $entry->steamid, $str );
$userXML = simplexml_load_string( file_get_contents( $userURL ) );
$username = $userXML->steamID;
$score = $entry->score;
$rank = $entry->rank;
$ugcid = $entry->ugcid;


echo "<tr><td>".$username."</td>";
echo "<td>".$score."</td>";
echo "<td>".$rank."</td>";
echo "<td>".$ugcid."</td></tr>";

$count++;
if( $count > $show_result_amount ){break;}
}
echo "</table>";
?>

Edited by ignace
removed [url] [/url]
Link to comment
Share on other sites

  • 5 months later...

Hi   quick old car,

 

I  am  in the same class as M dexter, I am  learnng code and script too, Very new infact.

 

I bring  data off a game server, which is .xml, and I mangered to write a script to make it work get get the result I wanted , well Kinda :)  I basically   have 5 x rows and 2 Columns. But now I  and trying to 5 columns

 

Is there any chance  of you helping me out. If so then I can post  my  code etc,

 

Thanks in advance

 

Macsure

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.