1

I want to request this URL translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=ar&multires=1&oc=3&prev=btn&ssel=0&tsel=0&sc=1

using PHP and reading the response. How ?

3 Answers 3

0

There are a number of options with cURL and readfile being the obvious ones.

0

You can use the file_get_contents() see http://php.net/manual/en/function.file-get-contents.php

But it is not as efficient as other methods to read remote files.

ie)

$mytranslation = file_get_contents("translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=ar&multires=1&oc=3&prev=btn&ssel=0&tsel=0&sc=1");
0

Use the Google Translate API instead of requesting an HTML page and parsing the HTML.

Sample:

GET https://www.googleapis.com/language/translate/v2?key=YOUR-API-KEY&source=en&target=de&q=Your%20text
2
  • 2
    "Important: Google Translate API v2 is now available as a paid service. The courtesy limit for existing Translate API v2 projects created prior to August 24, 2011 will be reduced to zero on December 1, 2011. In addition, the number of requests your application can make per day will be limited. Google Translate API v1 will be shut off completely on the same date (December 1, 2011);"
    – Bill
    Nov 27, 2011 at 19:43
  • Thx, good to know. But if it is used by a commercial application I think $20.00 for 1 million characters might be worth the money...
    – CodeZombie
    Nov 27, 2011 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.