Skip to content

Instantly share code, notes, and snippets.

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 trevorgreenleaf/1832bc23a1ac51d4ae5c5a277a8163c6 to your computer and use it in GitHub Desktop.
Save trevorgreenleaf/1832bc23a1ac51d4ae5c5a277a8163c6 to your computer and use it in GitHub Desktop.
Demo
<?php
// pass a url
function getStuff($url){
// go get the content from that url
// then convert the content to a php object
return json_decode(file_get_contents($url));
}
// get the person data
$person = getStuff('https://swapi.co/api/people/3');
print_r($person);
?>
<h1><?php echo $person->name; ?></h1>
<p> <?php echo $person->height; ?> <br>
<?php echo $person->hair_color; ?></p>
<?php
// get the homeworld of the user
$homeworld = getStuff($person->homeworld);
print_r($homeworld);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment