Skip to content

Instantly share code, notes, and snippets.

@travstoll
Created January 15, 2017 16:38
Show Gist options
  • Save travstoll/6c5d40a44ec847a249cc7672a726b7a3 to your computer and use it in GitHub Desktop.
Save travstoll/6c5d40a44ec847a249cc7672a726b7a3 to your computer and use it in GitHub Desktop.
View GitHub Repos in PHP with File_Get_Contents using GitHub API
<?
//post url
$url = "https://api.github.com/users/octocat/repos";
//set file_get_contents header info
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'User-Agent: PHP',
'Content-type: application/x-www-form-urlencoded'
]
]
];
//initiate file_get_contents
$context = stream_context_create($opts);
//make request
$content = file_get_contents($url, false, $context);
//decode response to array
$response_array = json_decode($content, true);
var_dump($response_array);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment