PHP

This PHP example requires support for JSON in PHP web server, please use PHP 5.2 or higher.

Initialize variables, make sure to use your own application key:

$apikey = "test_only"; // NOTE: replace test_only with your own key
$word = "peace"; // any word
$language = "en_US"; // you can use: en_US, es_ES, de_DE, fr_FR, it_IT
$endpoint = "http://thesaurus.altervista.org/thesaurus/v1";


Now invoke the remote service using CURL library:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$endpoint?word=".urlencode($word)."&language=$language&key=$apikey&output=json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);


Check that the request has been processed (http code = 200) and parse the received response:

if ($info['http_code'] == 200) {
  $result = json_decode($data, true);
  echo "Number of lists: ".count($result["response"])."<br>";
  foreach ($result["response"] as $value) {
    echo $value["list"]["category"]." ".$value["list"]["synonyms"]."<br>";
  }

} else echo "Http Error: ".$info['http_code'];
Dictionary | Terms and conditions | Privacy policy