我有這段代碼。而且我希望在每個位置都可以訪問。但我得到的結果作爲字符串。這裏是例子:使file_get_contents只返回我想要的
「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'];' – Rikesh
怎麼樣?因爲我直接在我的數組數據中獲取所有字符串。 –
這是一個json字符串,你需要將它解碼爲一個數組。 – Rikesh