query); // [0] = (define|d|mean|meaning) // [1] = WORD return "https://api.dictionaryapi.dev/api/v2/entries/en/".$query_terms[1]; } public function parse_results($response) { $json_response = json_decode($response, true); if(!empty($json_response)) { // Word not found if (array_key_exists("title", $json_response)) { return array( "title" => strip_tags(trim($json_response['title'])), "text" => strip_tags(trim($json_response['message'])) ); } // Grab first result if there are multiple $result = $json_response[0]; $definitions = array_slice($result['meanings'][0]['definitions'], 0, 3); // Word found $formatted_response = strip_tags(trim($result['meanings'][0]['partOfSpeech']))."
    "; foreach($definitions as $key => $def) { $formatted_response .= "
  1. ".strip_tags(trim($def['definition']))."
  2. "; } $formatted_response .= "
"; return array( "title" => strip_tags(trim($result['word']))." [".strip_tags(trim($result['phonetic']))."]", "text" => $formatted_response, "source" => strip_tags(trim($result['sourceUrls'][0])) ); } else { return array( "title" => "Whoops...", "text" => "No definitions could be loaded. Try again later." ); } } } ?>