Discuz教程网

PHP 在线翻译函数代码

[复制链接]
authicon dly 发表于 2011-9-5 20:23:37 | 显示全部楼层 |阅读模式
代码分享给大家

  1. <?
  2. /**
  3. * GOOGLE翻译 英汉
  4. *
  5. * @param string $text 翻译句
  6. * @return unknown
  7. */
  8. function googleTran($text){
  9. if(empty($text)) return "";
  10. sleep(1);//反间碟
  11. $wf=@file_get_contents('http://translate.google.cn/translate_t?sl=en&tl=zh-CN&text='.urlencode($text).'#');
  12. if (false===$wf||empty($wf)){
  13. return false;
  14. }

  15. //截取相关信息
  16. $return = "";
  17. $wf=strip_tags($wf,"<div>");
  18. $star=strpos($wf,"<div id=result_box dir="ltr">");
  19. if(false===$star){
  20. return false;
  21. }
  22. $end=strpos($wf,"</div><div id=clir>");
  23. if(false===$end){
  24. return false;
  25. }
  26. $return = strip_tags(substr($wf,$star,$end-$star));

  27. return iconv("GB2312","UTF-8",trim($return));

  28. }
  29. ?>
复制代码







上一篇:PHP 购物车实例
下一篇:PHP 购物车的例子
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 05:06

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表