definition.php 786 B

123456789101112131415161718192021222324
  1. <?php
  2. function definition_results($query, $response)
  3. {
  4. $split_query = explode(" ", $query);
  5. $reversed_split_q = array_reverse($split_query);
  6. $word_to_define = $reversed_split_q[1];
  7. $json_response = json_decode($response, true);
  8. if (!array_key_exists("title", $json_response))
  9. {
  10. $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
  11. $source = "https://dictionaryapi.dev";
  12. return array(
  13. "special_response" => array(
  14. "response" => htmlspecialchars($definition),
  15. "source" => $source
  16. )
  17. );
  18. }
  19. }
  20. ?>