arrays - trying to scrape data of json in php not working -
why won't work should scrape definition pp , won't work :/
<?php $json_output = file_get_contents("http://api.urbandictionary.com/v0/define?term=pp"); $json = json_decode($json_output, true); $chuck_noris = $json['list']['definition']; print_r($chuck_noris ); ?>
there still dimension inside $json['list']
(its still array). can use foreach values inside it:
$json_output = file_get_contents("http://api.urbandictionary.com/v0/define?term=pp"); $json = json_decode($json_output, true); foreach($json['list'] $list) { // $list hold each array inside `$json['list']` echo $list['definition'] . '<br/>'; }
or explicitly pointing first result:
echo $json['list'][0]['definition'];
Comments
Post a Comment