Skip to content

Instantly share code, notes, and snippets.

@lidocaine
Created July 19, 2019 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lidocaine/403326e7a41bcefc62e86a8aa8766c34 to your computer and use it in GitHub Desktop.
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
<?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