Heim > php教程 > php手册 > PHP在线翻译函数

PHP在线翻译函数

WBOY
Freigeben: 2016-06-21 08:53:36
Original
3585 Leute haben es durchsucht
<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>
Nach dem Login kopieren



Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage