Skip to content

Instantly share code, notes, and snippets.

@konratnox
Created March 1, 2019 07:57
Show Gist options
  • Save konratnox/10b5b94b4543403df756fb5ddc44a384 to your computer and use it in GitHub Desktop.
Save konratnox/10b5b94b4543403df756fb5ddc44a384 to your computer and use it in GitHub Desktop.
<?
define("BASE_URL", "http://ws3.morpher.ru/russian/declension");
function morphWord($resource, $method) {
$full_url = BASE_URL . "$resource";
$options = array(
CURLOPT_URL => $full_url,
CURLOPT_HTTPHEADER => array('Content-Type: application/json',
'Accept: application/json'),
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => "NetAngels API client 0.1"
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ( $status > 399 ) {
return null;
}
return json_decode($content);
}
morphWord("?s={$phrase}&format=json", "GET")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment