首页  >  文章  >  php教程  >  PHP在线翻译函数

PHP在线翻译函数

WBOY
WBOY原创
2016-06-21 08:53:363552浏览
<ol class="dp-xml">
<li class="alt"><span><span>01.</span><span class="tag"></span><span>    </span></span></li>
<li>
<span class="tag-name">02.</span><span>/**   </span>
</li>
<li class="alt"><span>03. * GOOGLE翻译 英汉   </span></li>
<li><span>04. *   </span></li>
<li class="alt"><span>05. * @param string $text 翻译句   </span></li>
<li><span>06. * @return unknown   </span></li>
<li class="alt"><span>07. */    </span></li>
<li><span>08.function googleTran($text){    </span></li>
<li class="alt"><span>09.    if(emptyempty($text)) return "";    </span></li>
<li><span>10.    sleep(1);    </span></li>
<li class="alt">
<span>11.    $</span><span class="attribute">wf</span><span>=@file_get_contents('http://translate.google.cn/translate_t?</span><span class="attribute">sl</span><span>=</span><span class="attribute-value">en</span><span>&</span><span class="attribute">tl</span><span>=</span><span class="attribute-value">zh</span><span>-CN&</span><span class="attribute">text</span><span>=</span><span class="attribute-value">'.urlencode($text).'</span><span>#');    </span>
</li>
<li>
<span>12.    if (</span><span class="attribute">false</span><span>===$wfemptyempty($wf)){    </span>
</li>
<li class="alt"><span>13.        return false;    </span></li>
<li><span>14.    }    </span></li>
<li class="alt"><span>15.    </span></li>
<li><span>16.    //截取相关信息     </span></li>
<li class="alt">
<span>17.    $</span><span class="attribute">return</span><span> = </span><span class="attribute-value">""</span><span>;    </span>
</li>
<li>
<span>18.    $</span><span class="attribute">wf</span><span>=</span><span class="attribute-value">strip_tags</span><span>($wf,"</span><span class="tag"><span class="tag-name">div</span><span class="tag">></span><span>");    </span></span>
</li>
<li class="alt">
<span>19.    $</span><span class="attribute">star</span><span>=</span><span class="attribute-value">strpos</span><span>($wf,"</span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">result_box</span><span> </span><span class="attribute">dir</span><span>=/"ltr/"</span><span class="tag">></span><span>");    </span></span>
</li>
<li>
<span>20.    if(</span><span class="attribute">false</span><span>===$star){    </span>
</li>
<li class="alt"><span>21.        return false;    </span></li>
<li><span>22.    }    </span></li>
<li class="alt">
<span>23.    $</span><span class="attribute">end</span><span>=</span><span class="attribute-value">strpos</span><span>($wf,"</span><span class="tag"></span><span class="tag-name">div</span><span class="tag">></span><span class="tag"><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">clir</span><span class="tag">></span><span>");    </span></span>
</li>
<li>
<span>24.    if(</span><span class="attribute">false</span><span>===$end){    </span>
</li>
<li class="alt"><span>25.        return false;    </span></li>
<li><span>26.    }    </span></li>
<li class="alt">
<span>27.    $</span><span class="attribute">return</span><span> = </span><span class="attribute-value">strip_tags</span><span>(substr($wf,$star,$end-$star));    </span>
</li>
<li><span>28.    </span></li>
<li class="alt"><span>29.    return iconv("GB2312","UTF-8",trim($return));    </span></li>
<li><span>30.    </span></li>
<li class="alt"><span>31.}    </span></li>
<li>
<span>32.</span><span class="tag">?></span><span>  </span>
</li>
</ol>



声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn