1

I'm trying to store the titles in an array and extract the long cmcontinue string from the below url.

http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:1980_births&format=json

my current code:

$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'};
mu is too short
436k71 gold badges863 silver badges822 bronze badges
asked Nov 25, 2012 at 5:36
1
  • What's the problem you're having? oh wait. You asked the question in perfect tune with your nickname :) Commented Nov 25, 2012 at 6:02

1 Answer 1

6

try adding second paremeter of json_decode, like:

$json = json_decode($c, true);

And get cmcontinue value as:

echo $json["query-continue"]["categorymembers"]["cmcontinue"];

For titles:

$titles = array();
foreach($json["query"]["categorymembers"] as $vals) {
 array_push($titles, $vals["title"]);
}
echo "<pre>"; print_r($titles);
answered Nov 25, 2012 at 6:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.