Created
July 19, 2019 16:23
-
-
Save lidocaine/403326e7a41bcefc62e86a8aa8766c34 to your computer and use it in GitHub Desktop.
A quick "middleman" function I wrote a while back while working on a discord bot in order to pull a random image from giphy based on a search term/s
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 | |
$tag = urlencode( $_GET['t'] ); | |
$giphyApiKey = 'dc6zaTOxFJmzC'; | |
$giphyURL = 'http://api.giphy.com/v1/gifs/random?api_key='.$giphyApiKey.'&tag='.$tag; | |
$giphy = json_decode( file_get_contents( $giphyURL ) ); | |
if ( $giphy->meta->status != 200 ) { | |
echo "**GiphyAPI Error: ".$giphy->meta->msg."**"; | |
} else { | |
if ( sizeof( $giphy->data ) > 1 ): | |
echo "**No results found.**"; | |
else: | |
echo $giphy->data->url; | |
endif; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment