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

PHP在线翻译函数

WBOY
Lepaskan: 2016-06-21 08:53:36
asal
3585 orang telah melayarinya
<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>
Salin selepas log masuk



Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan