0

我尝试输入 echo $steamrep_id 但没有运气,有人可以帮忙吗?代码:

<?php
class Steam_Rep_Rep {

    // cURL Variable
    private $ch = null;

    public function __construct() {
        // Setup cURL
        $this->ch = curl_init();
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 4);
    }    

    public function getUserInfo($steamrep_id) {
        // cURL
        curl_setopt($this->ch, CURLOPT_URL, "http://steamrep.com/api/beta/reputation/{$steamrep_id}?json=1");
        $result = curl_exec($this->ch);
        $xml = simplexml_load_string($result);

        if(!empty($xml)) {
            return array(
                'rep' => $xml->steamREP,

            );
        } else {
            return array(
                'rep' => "No reputation found",
            );
        }
    }
}
?>

基本上,它从 XML 文件中获取数据并将其存储在变量中。
另请注意,我是编码的半新手,我只是将其他代码的一部分并将其粘在一起以使其工作,我什至不确定它是否可以正常工作。编辑:不,我不会执行变量,我只会编写一个从变量中获取数据的代码,仅此而已。

4

2 回答 2

0

你有一些错误,STEAM_ID64用 STEAM_ID 替换它应该可以工作

class Steam_Rep_Rep {

    // cURL Variable
    private $ch = null;

    public function __construct() {
        // Setup cURL
        $this->ch = curl_init();
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 4);
    }    

    public function getUserInfo($steamrep_id) {
        // cURL
        curl_setopt($this->ch, CURLOPT_URL, "http://steamrep.com/api/beta/reputation/{$steamrep_id}?json=1");
        $result = curl_exec($this->ch);
        $xml = json_decode($result);
        if(!empty($xml->steamrep->reputation)) {
            return array(
                'rep' => $xml->steamrep->reputation,
            );
        } else {
            return array(
                'rep' => "No reputation found",
            );
        }
    }
}

$steam = new Steam_Rep_Rep();
$rep = $steam->getUserInfo('76561197971691194');
echo $rep['rep'];
于 2012-08-28T10:43:35.930 回答
0

尝试这个:

$test = new Steam_Rep_Rep();

$var = $test->getUserInfo("id_goes_here");

var_dump($var);

将其放在脚本的末尾,然后在浏览器中运行它。

于 2012-08-28T10:33:32.263 回答