在 json 中转换特殊字符串答案或在数据 PHP 中获取访问权限
convert special string answer in json or get access in data PHP
我有这个:-
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$R=file_get_contents($url);
print($R);
我得到:-
[[["Bonjour","hello",null,null,1] ] ,null,"en",null,null,null,1.0,[] ,[["en"] ,null,[1.0] ,["en"] ] ]
你能帮我访问 'Bonjour'
和 'en'
吗?
它是一个字符串,我正在尝试解码、取消编码等,但没有任何方法可以正常显示。
提前谢谢你
您收到的数据在 json 中,因此您应该对其进行解码。
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$result = file_get_contents($url);
$data = json_decode($result);
//print_r($data);
$bonjour = $data[0][0][0];
$en = $data[2];
echo $bonjour . ' ' . $en;
我有这个:-
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$R=file_get_contents($url);
print($R);
我得到:-
[[["Bonjour","hello",null,null,1] ] ,null,"en",null,null,null,1.0,[] ,[["en"] ,null,[1.0] ,["en"] ] ]
你能帮我访问 'Bonjour'
和 'en'
吗?
它是一个字符串,我正在尝试解码、取消编码等,但没有任何方法可以正常显示。 提前谢谢你
您收到的数据在 json 中,因此您应该对其进行解码。
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$result = file_get_contents($url);
$data = json_decode($result);
//print_r($data);
$bonjour = $data[0][0][0];
$en = $data[2];
echo $bonjour . ' ' . $en;