Home  >  Article  >  php教程  >  百度翻译类

百度翻译类

WBOY
WBOYOriginal
2016-06-07 11:45:041875browse

百度翻译开放api接口啦,你可以直接从百度翻译上获取翻译结果。这里写了一个类,要求支持curl扩展。
首先需要到http://developer.baidu.com/申请一个账号,然后创建一个应用,得到一个appkey。

用法示例:
$fanyi=new BaiduFanyi();
$fanyi->appkey="qgGlBmOGn……GWkyV";//申请到的appkey
//默认中译英
if(!$re=$fanyi->fanyi("我爱你,但是你爱我吗?")){
echo $fanyi->geterror();//如果有错误,调用这个函数得到错误信息
}else{
echo $re;
}
//中译日
echo $fanyi->fanyi("我爱你,但是你爱我吗?","zh","jp");
//日译英
echo $fanyi->fanyi("我爱你,但是你爱我吗?","jp","en");

附件 fanyi.zip ( 1.54 KB 下载:285 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn