制作了一个小php脚本,需要对其进行测试,但它不';默认情况下,我不会预先部署任何东西。如何使其输出?
我试着把echo$steamrep_id放进去,但运气不好,有人能帮忙吗?代码:制作了一个小php脚本,需要对其进行测试,但它不';默认情况下,我不会预先部署任何东西。如何使其输出?,php,xml,variables,Php,Xml,Variables,我试着把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, CUR
<?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文件中获取数据并将其存储在变量中。还请注意,我是一个半新手的编码,我只是采取了其他代码的一部分,并把它粘在一起,使这项工作,我甚至不知道它是否做它的工作。 编辑:不,我不会执行变量,我只会生成一个代码,从变量中获取数据,就这样。试试这个:
$test = new Steam_Rep_Rep();
$var = $test->getUserInfo("id_goes_here");
var_dump($var);
将其放在脚本末尾,然后在浏览器中运行。如果出现一些错误,请将
STEAM\u ID64
替换为STEAM\u 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'];
你真的在执行代码吗?你有新的Steam_Rep_Rep吗?如果你是新手,从新手开始,而不是XML解析和cURL调用。首先了解编程和PHP基础知识。在网上可以找到很多资源。如果我在这里替换id_,它会说:array(1){[“rep”]=>object(simplexmlement){3(0)},但是如果我在这里使用id_,它只会说array(1){[“rep”]=>string(19)“找不到信誉”},我需要它从XML文件中获取数据,不显示上面的内容:\n现在,它不只是从XML中获取数据,而是这样做:数组(1){[“rep”]=>string(32)“SR DONATOR,REDDIT ADMIN,SR ADMIN”}如果我要制作一些从变量获取数据的东西,它是否会取出SR DONATOR等等?是的。。这意味着用户在声誉中有3个标题,您可以通过
,
分解这些标题,例如:$all=explode(“,”,$rep)代码>警告:explode()希望参数2是字符串,数组在第37行的C:\Users\Arcaneex\Documents\NuSphere PhpED\Projects\noname2.php中给出这就是我现在得到的:(76561197971691194基本上,我只需要有2个变量,如果调用它们(就像读取变量一样)它将预先显示骗子状态或警告状态。修改..立即检查(添加echo$rep['rep'];
)