如何在PHP中获取数组内容
我试图在PHP中回显响应(数组),但它没有返回所需的值 这是我的密码如何在PHP中获取数组内容,php,arrays,Php,Arrays,我试图在PHP中回显响应(数组),但它没有返回所需的值 这是我的密码 <?php $id = $_GET['id']; $array = file_get_contents('http://wen.com/api.php?id='.$id); echo $array[0]; // it returns A, while I need Friday here echo $array[1]; // it returns r, while I need Tuesday, 17 November
<?php
$id = $_GET['id'];
$array = file_get_contents('http://wen.com/api.php?id='.$id);
echo $array[0]; // it returns A, while I need Friday here
echo $array[1]; // it returns r, while I need Tuesday, 17 November here
?>
编辑:
我在文件\u get\u内容中使用的api代码是:
$html = file_get_contents("$url");
$dom = new DomDocument();
$dom->loadHTML($html);
$dom_xpath = new DOMXpath($dom);
$elements = $dom_xpath->query('//span[@class="nowrap"]');
foreach($elements as $data){
$array[] = $data->nodeValue;
}
print_r($array);
已解决:
我刚刚替换了print\u r($array);通过echo json_编码($array) 看起来好像
file\u get\u contents
正在返回一个值为Array([0]=>Frid..
的字符串。这个文件是如何生成的,在类似JSON的东西中可能更好。似乎在APIreplaceprint\r($Array);
byecho JSON\u encode($Array)
$html = file_get_contents("$url");
$dom = new DomDocument();
$dom->loadHTML($html);
$dom_xpath = new DOMXpath($dom);
$elements = $dom_xpath->query('//span[@class="nowrap"]');
foreach($elements as $data){
$array[] = $data->nodeValue;
}
print_r($array);