我不太了解我需要用于 foreach 语句来处理此查询的参数。
知道为什么这个 foreach 不起作用吗?示例 faroo 查询: http ://www.faroo.com/api?q=%27elephants%27&start=1&length=10&l=en&src=web&f=json&jsoncallback=mycallback&key=y3EVs8B2ntbxXrmZWpBTDBueayA_&rlength=0
<?php
$ch = curl_init();
if ($_POST['query'])
{
$query = urlencode("'{$_POST['query']}'");
$fullUri = 'http://www.faroo.com/api?q='.$query.'&start=1&length=10&l=en&src=web&f=json&jsoncallback=mycallback&key=y3EVs8B2ntbxXrmZWpBTDBueayA_&rlength=0';
curl_setopt($ch, CURLOPT_URL, $fullUri);
echo $fullUri;
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($ch);
$js = json_decode($data);
$i=0;
foreach ($js -> results as $item)
{
$Faroo[$i] = "<a href=\"{$item->url}\">
{$item->title}</a>faroo
<p>$item->kwic}</p>";
$i++;
}
echo $Faroo[3];
}