kyroskoh

Twitch CustomAPI - Urban Dict

May 1st, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. // Set names to lowercase for URL injection.
  3. $TermLower = strtolower($_GET["Term"]);
  4. $UserLower = strtolower($_GET["User"]);
  5. // Inject lowercase names to get correct capitalization of usernames.
  6. $ch = curl_init("https://api.urbandictionary.com/v0/define?term=" . $TermLower);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. $result = curl_exec($ch);
  9. curl_close($ch);
  10. // Decode the above JSON data.
  11. $payload = json_decode($result, true);
  12. // No Term was entered after the command.
  13. if (empty($_GET["Term"]))
  14. {
  15. echo 'Error: ' . htmlspecialchars($_GET["Term"]) . ' is needed to be specify!';
  16. die();
  17. }
  18.  
  19. // Print the output.
  20. echo '(' . htmlspecialchars($_GET["User"]) . ') Definition of ' . $TermLower . ': ' . $payload->definition;
  21. ?>
  22.  
  23. Example: urbandict.php?Term=csgo&User=TwitchUsername
Add Comment
Please, Sign In to add comment