wiki:WordNetApiPhp
close Warning: Can't synchronize with repository "(default)" (/usr/local/svn/deb2-client does not appear to be a Subversion repository.). Look in the Trac log for more information.

Version 3 (modified by Adam, 16 years ago) (diff)

--

Example of DEBVisDic API usage in PHP.

Requirements: php-curl and php-json

<?
$server = 'https://deb.fi.muni.cz:9001/';
$user = 'test';
$password = 'test';

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_USERPWD, $user . ":" . $password);

#initialize, what dictionaries I have access to?
$url = $server.'doc?action=init';
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);

$dicts = json_decode($result, true);
foreach($dicts['slovniky'] as $dict_code => $dict_info) {
        #dictionary code + dictionary url
        $dict_url = $dict_info['dict'];
        echo $dict_code.':'.$dict_url."\n";

        #let's search for dogs
        $url = $server.$dict_url.'?action=queryList&word=dog';
        curl_setopt($curl, CURLOPT_URL, $url);
        $result = curl_exec($curl);
        $result_hash = json_decode($result, true);

        #and let's get XML for first three
        for($i = 0; $i < 3; $i++) {
                $id = $result_hash[$i]['value'];
                echo 'Getting XML for '.$result_hash[$i]['label']." with ID=$id\n";
                $url = $server.$dict_url.'?action=runQuery&query='.$id.'&outtype=plain';
                curl_setopt($curl, CURLOPT_URL, $url);
                $result = curl_exec($curl);
                $xml = json_decode($result);
                echo $xml."\n";
        }
}
?>