The example of this article tells the PHP Youdao translation API call method, here we use the File_get_contents function directly read by the API returned data processing, share for everyone reference. The specific analysis is as follows:
Before calling we need to apply for a Youdao translation API data interface key, address such as:
Copy Code code as follows:
Http://fanyi.youdao.com/openapi?path=data-mode
Method description, Data interface:
Copy Code code as follows:
http://fanyi.youdao.com/openapi.do?keyfrom=<keyfrom>&key=<key>&type=data&doctype=< Doctype>&version=1.1&q= the text to be translated
Parameter description:
Type-Returns the types of the result, fixed to data
DOCTYPE-Returns the data format of the result, XML or JSON or JSONP
Version-edition, current latest version is 1.1
Q-The text to be translated cannot exceed 200 characters and requires the use of UTF-8 encoding
ErrorCode:
0-Normal
20-The text to be translated is too long
30-Unable to perform a valid translation
40-Unsupported language type
50-Invalid Key
The PHP instance code is as follows:
Copy Code code as follows:
$url = "Http://fanyi.youdao.com/openapi.do?keyfrom=xujiangtao&key=1490852988&type=data&doctype=json &version=1.1&q= ". $content;
$list = file_get_contents ($url);
$js _de = Json_decode ($list, true);
Note: When using the API key, the request frequency is limited to 1000 times per hour, and the limit is banned.
If your application does require more than 1000 requests per hour, please contact translate-service@corp.youdao.com and provide details of your application, name, function, website address, how to use the API, API key, estimated frequency of access, Whether business behavior, screenshots, etc., and the application Access Youdao translation API used by the server IP, after the audit can be relaxed access restrictions.
I hope this article will help you with your PHP program design.