Last active
December 24, 2023 17:20
-
-
Save depoulo/ba2cb64702316a7b01d8 to your computer and use it in GitHub Desktop.
Get random gif from Giphy - might be against their TOS, please check yourself and use reasonably - I use it for our continuos integration status monitor, which of course is almost never red ;)
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
// get random image from Giphy | |
function getRandomGif($topic = 'fail') { | |
$data = file_get_contents("http://giphy.com/search/$topic"); | |
preg_match_all('@href="/gifs/(.*?)"@', $data, &$matches); | |
$gifId = $matches[1][array_rand($matches[1])]; | |
return "http://media2.giphy.com/media/$gifId/giphy.gif"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Giphy have an API too!
👍
Note: not the best clean and robust way for a HTTP call... Guzzle?