Today to a small program to write backstage, by invoking the Baidu translation API to achieve the translation function.
Call the URL of Baidu API ' http://openapi.baidu.com/public/2.0/translate/dict/simple?client_id= your key&q= to check the Chinese &from=zh &to=en ';
Application procedure See click Open link
Above is the preparatory work
===================================================================================================
The JSON translated by calling Baidu Translator is: {"errno": 0, "data": {"Word_name": "\u4f60\u597d", "symbols": [{"Ph_zh": "N\u01d0 H\u01ceo", " Parts ": [{" "": "", "means": ["Hello", "hi", "How does You Do!"]}]}]}, "to": "en", "from": "ZH"} '
A classmate with bad eyesight can format a string
{"errno": 0, "data": {"Word_name": "\u4f60\u597d", "symbols": [{"Ph_zh": "N\u01d0 H\u01ceo", "parts": [{"part": "", "means ": [" Hello "," hi "," How does You Do! "]}]}]}, ' to ': ' en ', ' from ': ' ZH '}
Key statement: Json_decode ($jsonResult)->data->symbols[0]->parts[0]
Also blame me too stupid, just such a statement toss me all night ... The foundation is too important!!!
Through this step, we get the
{"part": "", "means": ["Hello", "hi", "How does You Do!"]}
Next through
$JSONOBJ->means[0] $jsonObj->means[1] $JSONOBJ->means[2]
Get the 3 definitions of "Hello" separately.
In the actual operation, the whole interpretation can be obtained through the loop statement.
Here's all the code
Data->symbols[0]->parts[0];echo $jsonObj->means[0]. '
' Echo $jsonObj->means[1]. '
' Echo $jsonObj->means[2]. '
';? >
Input url?s= Hello
Run results