xkcdInfo
This file contains 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 | |
/************************************************* | |
** xkcdInfo for explainxkcd.com ** | |
** Version: 1.0.0 ** | |
** Developed by Yirba <yirba3 AT gmail DOT com> ** | |
** Created: 2 August 2012 ** | |
** Last modified: 2 August 2012 ** | |
*************************************************/ | |
//get data | |
$data = $_GET['input']; | |
//get user input | |
$input = explode(":", $data); | |
//separate variables | |
$var = explode("-", $input[1]); | |
//retrieve xkcd JSON | |
if ($var[0] == 0) { | |
$json = file_get_contents("http://xkcd.com/info.0.json"); | |
} | |
else { | |
$json = file_get_contents("http://xkcd.com/$var[0]/info.0.json"); | |
} | |
//decode JSON | |
$decoded = json_decode($json, true); | |
//check if user wants to embed the comic image | |
if ($var[1] == "embed") { | |
//output image | |
echo '<img src="' , $decoded['img'] , '" title="' , $decoded['alt'] , '" alt="' , $decoded['safe_title'] , '">'; | |
} | |
else { | |
//output decoded JSON | |
echo $decoded[$var[1]]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment