PHP Simple HTML DOM Outputting Blank Page

£可爱£侵袭症+ 提交于 2019-12-11 09:19:00

问题


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!


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/16109213/php-simple-html-dom-outputting-blank-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!