Warning: strncmp() has been disabled for security reasons in /www/web/default/blog/public_html/wp-includes/formatting.php on line 117
Warning: strncmp() has been disabled for security reasons in /www/web/default/blog/public_html/wp-includes/formatting.php on line 117
Warning: strncmp() has been disabled for security reasons in /www/web/default/blog/public_html/wp-includes/formatting.php on line 117
Warning: strncmp() has been disabled for security reasons in /www/web/default/blog/public_html/wp-includes/formatting.php on line 117
php利用谷歌实现自动翻译,以下是两种实现的方式,php文档用utf8就不会出现乱码问题
第一种利用curl:
function translate($text,$language='zh-cn|en'){
if(empty($text))return false;
@set_time_limit(0);
$html = "";
$ch=curl_init("http://google/translate_t?langpair=".urlencode($language)."&text=".urlencode($text));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$html=curl_exec($ch);
if(curl_errno($ch))$html = "";
curl_close($ch);
if(!empty($html)){
$x=explode("
",$html);
发布评论