【发布时间】:2014-06-16 09:17:00
【问题描述】:
我有这个代码。我希望在每个职位上都可以访问。但我得到的结果是字符串。这是一个例子:
"string(7652)"{"id":"34","nume":"STUDENT","bilet":null,"log":"2014-06-16 11:41:28\n2014- 06-16 11:41:30\n2014-06-16 11:41:41\n2014-06-16 11:41:41\n2014-06-16 11:41:43\n2014-06-16 11:42 :03\n2014-06-16 11:42:05\n2014-06-16 11:42:06\n2014-06-16 11:42:06\n2014-06-16 11:42:06\n2014-06 -16 11:42:09\n2014-06-16 11:42:11\n2014-06-16 11:42: "
我只需要日志......所以我可以用这些日志制作一个 heml 表。想法?
public $datte = array();
public function aduDpServer(){
$data = array ('foo' => 'bar', 'id' => 34);
$data = http_build_query($data);
$context_options = array (
/*'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($data) . "\r\n",
'content' => $data
) */
'http'=> array(
'method'=>'POST',
'header'=>"Content-type: application/x-www-form-urlencoded\r\n",
'content'=>$data
)
);
$context = stream_context_create($context_options);
$this->datte = file_get_contents('http://www.jajaja/x/updt.php', false, $context);
//var_dump($fp);
}
public function afiseaza(){
//print_r($this->datte);
echo"<table border=1 cellpading=0 cellspacing=0 >";
echo"<th>Accesari</th>";
$this->datte = is_array($this->datte) ? $this->datte: array($this->datte); //fortare vector
foreach ($this->datte as $d) {
echo"<tr>";
echo"<td>".$d."</td>";echo"<br>";
echo"</tr>";
}
}
【问题讨论】:
-
你需要循环遍历
$this->datte['log']; -
怎么样?因为我直接在我的数组 datte 中获得了所有字符串。
-
这是一个 json 字符串,您需要将其解码为数组。
标签: php file-get-contents