Home > Backend Development > PHP Tutorial > PHP 在线翻译函数代码_php实例

PHP 在线翻译函数代码_php实例

WBOY
Release: 2016-06-07 17:26:23
Original
810 people have browsed it

代码分享给大家

复制代码 代码如下:


/**
* 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));

}
?>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template