function translate($string)
{
$url = 'https://translate.yandex.net/api/v1.5/tr.json/translate?';
$aParams = array();
$aParams['key'] = 'ключ';
$aParams['text'] = $string;
$aParams['lang'] = 'ru-en';
$aParams['format'] = 'plain';
$url = $url . http_build_query($aParams);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, 156, 5000);
curl_setopt($ch, CURLOPT_ENCODING , "");
$data = curl_exec($ch);
curl_close($ch);
if (strlen($data))
{
$oData = json_decode($data);
if (is_object($oData) && $oData->code == 200 && isset($oData->text[0]))
{
return $oData->text[0];
}
}
return NULL;
}