Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created August 10, 2016 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Echocage/bd21818faf5b2bc86a08fbe2f9e9fa93 to your computer and use it in GitHub Desktop.
Save Echocage/bd21818faf5b2bc86a08fbe2f9e9fa93 to your computer and use it in GitHub Desktop.
$text = "this is test sentence to see if this works";
$source = "auto";
$target = "pl";
$regex = '/"([^+,+$]+)"/';
$textEncode = urlencode($text);
$response = file_get_contents("http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$target&dt=t&q=$textEncode");
$response = preg_replace('/,+/', ',', $response);
$response = preg_replace('/\[,/', '[', $response);
$responseArray = json_decode($response);
$response_text = $responseArray[0][0][0];
print_r($response_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment