Last active
August 29, 2015 14:22
-
-
Save LukeXF/920794667bec2cb65eee to your computer and use it in GitHub Desktop.
Jleeto
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 | |
/** | |
* convert each of the APIs from JSON to Array | |
* @param string | |
* @return array | |
*/ | |
function convertAPI($url) { | |
$api = $url; | |
$api_response = file_get_contents($api); // get content of url | |
$api = json_decode($api_response); // decode from JSON | |
$api = objectToArray($api); // convert from object to PHP array | |
return $api; // return the API | |
} | |
/** | |
* returns an array or object to an array | |
* @param object or array | |
* @return array | |
*/ | |
function objectToArray($d) { | |
if (is_object($d)) { // if object, output array | |
$d = get_object_vars($d); | |
} | |
if (is_array($d)) { // if messed up array, output array | |
return array_map(__FUNCTION__, $d); | |
} else { | |
return $d; // output array if normal array | |
} | |
} | |
/** | |
* outputs an array in a formatted view | |
* @param object or array | |
*/ | |
function debug($array) { | |
echo "<pre>"; | |
print_r($commands); | |
echo "</pre>"; | |
} | |
/** | |
* loops through all the commands a given amount of times | |
* @param object or array, integer | |
*/ | |
function loopCommands($array, $amount = false) { | |
$i = 0; | |
$count = count($array); | |
// if $amount equals true | |
if ($amount){ | |
$count = $amount; // makes the int the amount set | |
} else { | |
$count = count($array); // makes an int the amoutn of commands in the array | |
} | |
// now we're going to loop though the data | |
while ($i < $count) { | |
echo " | |
<div class='col-md-4'> | |
<div class='panel panel-success'> | |
<div class='panel-heading'>" . $array[$i]["command"] . "</div> | |
<div class='panel-body'> | |
" . $i . " | |
</div> | |
</div> | |
</div> | |
"; | |
echo $array[$i]["command"]; | |
echo "<br>"; | |
$i++; // add one | |
} | |
} | |
?> |
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 | |
require_once('functions.php'); // load the functions page | |
// use the functions here | |
$commands = convertAPI("http://jleeto.me/mcommand/minecraftcommands.json"); | |
// output array | |
echo "<div class='container'>"; | |
echo "<div class='row'>"; | |
loopCommands($commands); | |
echo "</div>"; | |
echo "</div>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment