2011-07-06 15 views
3

あなたはこのGETまたはPOST時:それをデコードする方法Googleを解読する方法は、PHPで応答を翻訳しますか?

[[["автомобил","car","avtomobil",""]],,"en",,[["автомобил",[5],1,0,1000,0,1,0]],[["car",5,[["автомобил",1000,1,0],["автомобилот",0,1,0],["автомобили",0,1,0],["кола",0,1,0],["возило",0,1,0]],[[0,3]],"car"]],,,[["en","fr"]],30]

"http://translate.google.com/translate_a/t","client=t&sl=auto&tl=".urlencode($lang)."&text=".urlencode($text)

を応答は次のようになりますか? (おそらくjson_decode形式)

+3

あなたはjson_decodeを試してみましたか? –

+0

json_decode()はNULLを返します – pankipan4e

答えて

0

PHPのjson_decode functionを使用して、そのデータをネイティブのPHPデータ型に変換してみてください。 JSONを返すためにAPIが

client=p 
+0

json_decode()はNULLを返します – pankipan4e

+0

google urlの部分でclient = pを使用して最初にjson_decode funを有効にしてください –

9
//if the answer was usefull please do not forget to vote up! thanks. 
+0

クライアントパラメータは何を意味していますか?文書がありますか?ありがとうございました! – meteorgan

+0

私は完全には分かりませんが、それは文書化されていない機能です。 – puromonogatari

+1

あなたの答えは私を大いに助け、私は完全な答えを添付しました。 –

2
//this will translate from en to ar -- you can change it for your needs 
function translate_word($en){ 
    $file_content = file_get_contents('http://translate.google.com/translate_a/t?client=p&sl=auto&tl=ar&hl=en&sc=2&ie=UTF-8&oe=UTF-8&uptl=ar&oc=1&prev=conf&psl=auto&ptl=en&otf=1&it=sel.8936&ssel=0&tsel=3&q='.str_replace(" ","%20",$en)); 
    $obj = json_decode($file_content); 
    if(!empty($obj->sentences[0]->trans)){ 
     return $obj->sentences[0]->trans; 
    }else{ 
     return $en; 
    } 
} 
//how to use 
echo translate_word("test translation process"); 
//if you do not know short codes for your language you can just open 

translate.google.comとスクリーンショット

//you should have firebug extension installed on your browser 

enter image description hereで説明さんにパラメータ

client=t 

を変更得るために

関連する問題