<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="PHP结合谷歌的Translate API实现自己的翻译脚本的示例代码" id="card1">
<p> 游客</p><p>
标题:PHP结合谷歌的Translate API实现自己的翻译脚本的示例代码<br/>
正文:<br/>
PHP代码：代码如下:#!/usr/bin/php -q<br/>&amp;lt;?php<br/>/** <br/> * PHP Script For Google Translate<br/> * @author:Yishan Wang<br/> * @version:1.0.0<br/> */<br/>class Google_API_translator<br/>{<br/> public $url = &quot;http://translate.google.com/translate_t&quot;;<br/> public $text = &quot;&quot;;<br/> public $out = &quot;&quot;;<br/> public $ip = '';<br/> function setText($text){<br/>  $this-&amp;gt;text = $text;<br/> }<br/> function translate($from='auto',$to='zh-CN'){<br/>  $this-&amp;gt;out = &quot;&quot;;<br/>  $gphtml = $this-&amp;gt;postPage($this-&amp;gt;url, $this-&amp;gt;text,$from,$to); //@camnpr<br/>  preg_match_all('/&amp;lt;span/s+title/=&quot;[^&amp;gt;]+&amp;gt;([^&amp;lt;]+)&amp;lt;//span&amp;gt;/i',$gphtml,$res);<br/>  $this-&amp;gt;out = $res[1][0];<br/>  return $this-&amp;gt;out;<br/> }<br/> /*<br/> $from  需要翻译的语言<br/> $to    翻译的语言<br/> */<br/> function postPage($url, $text,$from='auto',$to='zh-CN'){<br/>&amp;n<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1710&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1710&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1710&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1710&amp;Page=3">[3]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1710&amp;Page=4">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1710">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1710">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>