$animal = mysqli_query($connect, "SELECT * FROM dictionaryread WHERE teacherid = $teacher_id ORDER BY id ASC LIMIT 10");
$fett = mysqli_fetch_array($animal);
foreach ($animal as $animall) {
$mett = $animall['metin'];
$bolunmus = explode(" ", $mett);
$ahmet = $bolunmus[0] ;
$apiKey = 'API_KEY_KODUM';
$text = "$ahmet";
$url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($text) . '&source=en&target=tr';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
$responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); //Here we fetch the HTTP response code
curl_close($handle);
if($responseCode != 200) {
echo 'Fetching translation failed! Server response code:' . $responseCode . '
';
echo 'Error description: ' . $responseDecoded['error']['errors'][0]['message'];
}
else {
echo ' '.$ahmet.'
';
}}
?>