Last active
October 18, 2016 14:36
-
-
Save skorotkiewicz/f3a1eb4bf30f1a8e4b6061b652a9757e to your computer and use it in GitHub Desktop.
PHP Function for API Memetrash
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 | |
function lolz($msg) { | |
$text = ereg_replace("[^A-Za-z0-9 ]", "", $msg); | |
$text = substr($text, 0, 64); | |
$curlchanel = curl_init("https://api.memetrash.co.uk/cat"); | |
curl_setopt($curlchanel, CURLOPT_TIMEOUT, 6); | |
curl_setopt($curlchanel, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curlchanel, CURLOPT_POSTFIELDS, trim("text=$text")); | |
$wynik=curl_exec($curlchanel); | |
curl_close($curlchanel); | |
$json = json_decode($wynik, true); | |
if(filter_var($json['data']['images'][0], FILTER_VALIDATE_URL) === FALSE) { | |
$result = 'Erroz, such Lolz!'; | |
} else { | |
$result = $json['data']['images'][0]; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment