PHP Online translation function

Source: Internet
Author: User
Tags php online return
 
 
  1. 01.<?
  2. 02./**
  3. * Google Translate English and Chinese
  4. 04. *
  5. * @param string $text translating sentence
  6. * @return Unknown
  7. 07. */
  8. 08.function Googletran ($text) {
  9. if (Emptyempty ($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=== $wfemptyempty ($WF)) {
  13. return false;
  14. 14.}
  15. 15.
  16. 16.//Interception of relevant information
  17. $return = "";
  18. $WF =strip_tags ($WF, "<div>");
  19. $star =strpos ($WF, "<div id=result_box dir=/" ltr/">");
  20. if (false=== $star) {
  21. return false;
  22. 22.}
  23. $end =strpos ($WF, "</div><div id=clir>");
  24. if (false=== $end) {
  25. return false;
  26. 26.}
  27. $return = Strip_tags (substr ($WF, $star, $end-$star));
  28. 28.
  29. Return Iconv ("GB2312", "UTF-8", Trim ($return));
  30. 60K
  31. 31.}
  32. 32.?>






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.