Created
March 1, 2019 07:57
-
-
Save konratnox/10b5b94b4543403df756fb5ddc44a384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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