Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
class Translation
{
const DETECT_YA_URL = 'https://translate.yandex.net/api/v1.5/tr.json/detect';
const TRANSLATE_YA_URL = 'https://translate.yandex.net/api/v1.5/tr.json/translate';
private static $key ="AIza1yCf2zgkmk-nRxdbB4gg49M9GZhmFei55uo";
//private $key ="AIza1yCf2zgkmk-nRxdbB4gg49M9GZhmFei55uo";
function __construct() {
if (empty(self::$key)) {
throw new ErrorException("Field key is required");
} else {
echo self::$key;
}
}
public static function translate_text($format="text")
{
$values = array(
'key' => self::$key,
//'text' => htmlspecialchars($_GET["text"]),
//'lang' => htmlspecialchars($_GET["lang"]),
'format' => $format == "text" ? 'plain': $format
);
echo $values['key'];
echo "\n";
echo $values['format'];
echo "\n";
$formData = http_build_query($values);
echo $formData;
$ch = curl_init(self::TRANSLATE_YA_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formData);
$json = curl_exec($ch);
curl_close($ch);
}
}
//$transl = new Translation();
Translation::translate_text();
//echo $transl->translate_text();
//Translation::translate_text();