このPHPコードは100%動作しますが、以下の結果が表示されますが、このデータを個々のアイテムとしてどのように使用できますか?PHP/CURL/JSON:変数を代入する
は、私は次のようなものを使用することに慣れている:
$title = $data['selection3']['name'];
echo $title
しかし、それは、ここでは動作しません。私はそれを使って広告を作ることができるように、各項目を分離してvarに割り当てることができるようにしたいと思います。
PHPカールコード:
<?php
function origin($projecttoken,$apikey,$format) {
$ch = curl_init();
$apiuri = 'https://www.parsehub.com/api/v2/projects/'.$projecttoken.'/last_ready_run/data?api_key='.$apikey.'&format='.$format.'';
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_ENCODING, '');
if(curl_exec($ch) === false){
echo curl_error($ch) . '<br />';
}
$data = curl_exec($ch);
curl_close($ch);
return($data);
}
?>
<pre>
<?php
print_r(origin('xxxxxx','xxxxxx','json'));
?>
</pre>
結果:
{
"selection3": [
{
"name": "Medal of Honor™ Pacific Assault",
"url": "https://www.origin.com/usa/en-us/store/medal-of-honor/medal-of-honor-pacific-assault/standard-edition"
},
{
"name": "Join the Fight for Freedom"
},
{
"name": "This World War II shooter is On the House and yours to own totally free."
},
{
"name": "FREE"
},
{
"name": "Get It Now",
"url": ""
}
],
"selection6": [
{
"name": "Battlefield 4™ Dragon's Teeth",
"url": "https://www.origin.com/usa/en-us/store/battlefield/battlefield-4/expansion/battlefield-4-dragons-teeth"
},
{
"name": "Upgrade Your Fight"
},
{
"name": "Add this expansion to your library for free and dominate the battlefield. It's On the House! (Requires base game to play.)"
},
{
"name": "FREE"
},
{
"name": "Get It Now",
"url": ""
}
]
}