Skip Navigation

Pulling Data from SWAPI with PHP

This is small snippet to show you how you might get started pulling data from an api with 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('');


<h1><?php echo $person->name; ?></h1>
<p> <?php echo $person->height; ?> <br>
	<?php echo $person->hair_color; ?></p>


// get the homeworld of the user
 $homeworld = getStuff($person->homeworld);

Related Snippets

See all