Home >Backend Development >PHP Tutorial >PHP 在线翻译函数代码_PHP

PHP 在线翻译函数代码_PHP

WBOY
WBOYOriginal
2016-06-01 12:23:561892browse

代码分享给大家
复制代码 代码如下:

/**
* GOOGLE翻译 英汉
*
* @param string $text 翻译句
* @return unknown
*/
function googleTran($text){
    if(empty($text)) return "";
    sleep(1);//反间碟
    $wf=@file_get_contents('http://translate.google.cn/translate_t?sl=en&tl=zh-CN&text='.urlencode($text).'#');
    if (false===$wf||empty($wf)){
        return false;
    }

    //截取相关信息
    $return = "";
    $wf=strip_tags($wf,"

");
    $star=strpos($wf,"
");
    if(false===$star){
        return false;
    }
    $end=strpos($wf,"
");
    if(false===$end){
        return false;
    }
    $return = strip_tags(substr($wf,$star,$end-$star));

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

}
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn