我正在尝试将标题存储在数组中,并从下面的网址中提取长cm连续字符串。
我目前的代码:
$url = 'http://en.wikipedia.org/w/api.php?
action=query&list=categorymembers&cmtitle=Category:'.$cat.'&format=json';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "asdf");
$c = curl_exec($ch);
$json = json_decode($c);
$array = $json->{'query'}->{'categorymembers'}->{'title'};
答案 0 :(得分:5)
尝试添加json_decode的第二个参数,例如:
$json = json_decode($c, true);
获取cmcontinue
值为:
echo $json["query-continue"]["categorymembers"]["cmcontinue"];
titles
:
$titles = array();
foreach($json["query"]["categorymembers"] as $vals) {
array_push($titles, $vals["title"]);
}
echo "<pre>"; print_r($titles);