2022-02-19 12:40:56 -08:00
|
|
|
<?php
|
2023-08-21 08:29:50 -07:00
|
|
|
class DefinitionRequest extends EngineRequest {
|
2023-08-22 10:41:02 -07:00
|
|
|
|
2023-08-21 08:29:50 -07:00
|
|
|
public function get_request_url() {
|
|
|
|
$split_query = explode(" ", $this->query);
|
2022-02-19 12:40:56 -08:00
|
|
|
$reversed_split_q = array_reverse($split_query);
|
|
|
|
$word_to_define = $reversed_split_q[1];
|
2023-08-21 08:29:50 -07:00
|
|
|
return "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_results() {
|
|
|
|
$response = curl_multi_getcontent($this->ch);
|
2022-02-19 12:40:56 -08:00
|
|
|
|
|
|
|
$json_response = json_decode($response, true);
|
|
|
|
|
|
|
|
if (!array_key_exists("title", $json_response))
|
|
|
|
{
|
|
|
|
$definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
|
|
|
|
|
2022-04-01 02:22:26 -07:00
|
|
|
$source = "https://dictionaryapi.dev";
|
2022-03-03 01:32:46 -08:00
|
|
|
return array(
|
|
|
|
"special_response" => array(
|
2022-05-15 01:34:46 -07:00
|
|
|
"response" => htmlspecialchars($definition),
|
2022-03-03 01:32:46 -08:00
|
|
|
"source" => $source
|
|
|
|
)
|
|
|
|
);
|
2022-02-19 12:40:56 -08:00
|
|
|
}
|
2022-03-01 08:28:37 -08:00
|
|
|
|
2023-08-21 08:29:50 -07:00
|
|
|
}
|
2022-02-19 12:40:56 -08:00
|
|
|
}
|
2022-05-15 01:34:46 -07:00
|
|
|
?>
|