Created
August 30, 2018 03:17
-
-
Save trevorgreenleaf/1832bc23a1ac51d4ae5c5a277a8163c6 to your computer and use it in GitHub Desktop.
Demo
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 | |
// 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