Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Last active October 18, 2016 14:36
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 skorotkiewicz/f3a1eb4bf30f1a8e4b6061b652a9757e to your computer and use it in GitHub Desktop.
Save skorotkiewicz/f3a1eb4bf30f1a8e4b6061b652a9757e to your computer and use it in GitHub Desktop.
PHP Function for API Memetrash
<?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