Created
June 19, 2017 14:57
-
-
Save rainbow23/edc45192f13b9184c56cb19cbde191c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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