Skip to content

Instantly share code, notes, and snippets.

@rainbow23
Created June 19, 2017 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rainbow23/edc45192f13b9184c56cb19cbde191c6 to your computer and use it in GitHub Desktop.
Save rainbow23/edc45192f13b9184c56cb19cbde191c6 to your computer and use it in GitHub Desktop.
<?php
#http://geoapi.heartrails.com/api.html
$base_url = 'https://qiita.com';
$base_url2 = 'http://geoapi.heartrails.com/api/json?method=getPrefectures';
// エラーの場合も取得する設定にする
$context = stream_context_create(array(
'http' => array('ignore_errors' => true)
));
//$tag = 'PHP';
$tag = 'PHP_error'; // 存在しないタグ(ステータスコード:404)
$query = ['page'=>'1','per_page'=>'5'];
$response = file_get_contents(
$base_url2.$tag
,false
,$context
);
/*
$response = file_get_contents(
$base_url.'/api/v2/tags/'.$tag.'/items?'.
http_build_query($query)
,false
,$context
);
*/
$response2 = file_get_contents($base_url2);
// https://qiita.com/api/v2/tags/PHP/items?page=1&per_page=5
// 結果はjson形式で返されるので
$result = json_decode($response,true);
$result2 = json_decode($response2);
var_dump($result);
//var_dump($result2);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment