1

So, I am attempting to output the playtimes of a person playing L4D2 (game ID 550) and while this script used to work, it now only outputs a blank page using this "PHP Simple HTML DOM" I had backed up here http://rghost.net/45405596. If I download and try to use the newest simple dom from their website instead of showing nothing it shows

Call to undefined function file_get_dom() on line 9"

Here is the code I am running

    <?php
    ini_set('memory_limit', '-1');
    include('simple_html_dom.php');
    $lines = file('profile2.txt');                                                       //reads in the file with the list of user numbers
    foreach ($lines as $usernumber) {                                                  //loops line by line
    $link = "http://steamcommunity.com/profiles/<sitenumber>/games?tab=all";   //link format
    $link = preg_replace('/(<sitenumber>)/i',$usernumber,$link);               //puts usernumber into link format
    $link = preg_replace('/\s*/m','',$link);                                   //remove the stupid space
    $html = file_get_dom($link);                                               //calls the dom function
    $divline = $html->find('div[id=game_550] h5', 0);                          //finds the div block and then the h5 line
    $divline = preg_replace('/(<(\/)?h5>)/i', '', $divline);                   //replaces the <h5> tag with nothing
    if ($divline != '') {
        list($hrs,$u1,$u2,$u4) = explode(" ",$divline);
        if (($hrs < 90) && ($hrs > 1)) {
            echo $hrs." - ".$link."<br>";                                  //prints results
        }
    }
    $html->__destruct();
    unset($html); 
while(@ob_end_clean()); 


}
?>

This points to a text file named profile3.txt which contains this number "76561198049810642"

Any suggestions as to why this is outputting nothing? Thanks a ton!

4
  • Is there a reason you're not using the Steam Web API? Commented Apr 19, 2013 at 16:27
  • Two reasons. The first one is I have no idea how to use it and I know how to use Simple Dom (at least I thought I did). Second off when I DID try to use the API the only page I could get to work which was api.steampowered.com/IPlayerService/GetOwnedGames/v0001/… it output this in plaintext without any sort of formatting pastebin.com/NegPtvcJ and I have no idea how to sort that mess into just showing the Playtimeforever for game 550 Commented Apr 19, 2013 at 16:30
  • That's not "plaintext"; that's JSON. There's a PHP function called json_decode() that will allow you to parse that output with ease. Commented Apr 19, 2013 at 16:31
  • hmm, guess I don't know much when it comes to json. Is there a way I could get a simple example of how to use json_decode() to do what I am trying to do above? In short I am trying to output the Playtimeforever for an appid of 550, if you need I could email my steamkey. Thanks! Commented Apr 19, 2013 at 16:38

1 Answer 1

2

Here is some (untested) code that should help you get started using the Steam Web API:

$api_key = '...';
$steam_id = '...';
$game_id = 550;

$json = file_get_contents('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=' . $api_key . '&steamid=' . $steam_id . '&format=json');

$data = json_decode($json);
foreach ($data->response->games as $game) { 
    if ($game->appid == $game_id) {
        echo 'Playtime for ', $game_id, ' is ' . $game->playtime_forever;
    }
}
Sign up to request clarification or add additional context in comments.

7 Comments

Amazing xD People here are so much smarter then me lol. I will give this a shot and post the finished code incase anyone else like me needs help. As long as I can figure it out
$something is called a variable. You can store the playtime in hours in a variable using $playtime = $game->playtime_forever / 60;;
So, question. pastebin.com/ReXGyY4h. Made some small tweaks to your code, it worked like a charm by the way. My current question is, Is there a way to implement the last bit of code where it only shows things under a certain hour amount. In this case it would be under a certain minute amount since the API outputs in minutes. I can't figure out how it declares playtime_forever so I am unable to do logic on it. (reposed question to people know what I was talking about, previous link had my steam key xD)
@SuperMar1o: Not a problem. Remember to mark the question as correct by clicking the green check-mark by my answer.
I have another question regarding the filtering results, should I make another question with this since it is somewhat different? Also, where should I put the $playtime = xxx line at in the file? Anywhere I put it causes errors.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.