日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

php调用谷歌翻译接口_PHP调用谷歌翻译

發(fā)布時(shí)間:2023/12/10 php 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php调用谷歌翻译接口_PHP调用谷歌翻译 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

public $url = "http://translate.google.com/translate_t";

public $text = "";//帶翻譯內(nèi)容

public $out = "";//輸出內(nèi)容

public function setText($text)

{

$this->text = $text;

}

public function translate()

{

$this->out = "";

$gphtml = $this->postPage($this->url,$this->text);

var_dump($gphtml);exit;

//提取翻譯結(jié)果

$out = substr($gphtml,strpos($gphtml,''));

$out = substr($out,29);

$out = substr($out,0,strpos($out,''));

$this->out = $out;

return $this->out;

}

public function postPage($url,$text)

{

$html = '';

if($url != '' && $text != ''){

$ch = curl_init($url);

curl_setopt($ch,CURLOPT_REFERER,1);

curl_setopt($ch,CURLOPT_HEADER,1);

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);

curl_setopt($ch,CURLOPT_TIMEOUT,15);

$fields = array('hl=zh-CN', 'langpair=zh-CN|en', 'ie=UTF-8','text='.urlencode(mb_convert_encoding($text, 'UTF-8', 'GB2312')));

curl_setopt($ch,CURLOPT_POST,1);

curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $fields));

$html = curl_exec($ch);

if(curl_errno($ch)) $html = "curl_error";

curl_close($ch);

}

return $html;

}

}

//just for test

$g = new Google_API_translator();

$g->setText('我是誰!');

$g->translate();*/

function gtranslate($text,$to='zh-CN'){$entext = urlencode($text);$url = 'https://translate.google.cn/translate_a/single?client=gtx&dt=t&ie=UTF-8&oe=UTF-8&sl=auto&tl='.$to.'&q='.$entext;set_time_limit(0);$ch =curl_init();

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_MAXREDIRS,20);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);

curl_setopt($ch, CURLOPT_URL, $url);$result = curl_exec($ch);

curl_close($ch);$result = json_decode($result);if(!empty($result)){foreach($result[0] as $k){$v[] = $k[0];

}return implode(" ", $v);

}

}$longtext = "Why Should You Get Our Smart Trainer for your Little Munchkin?

Upgraded Soft Waterproof Skin-Friendly Material: High-quality swimwear fabric and TPU film wrap which looks like leather but touches like skin. Fast dry and the bacteria are hard to breed on this foam baby swim float. Non-inflatable Air-Free Swim Trainer is the safest and durable float available in the market today

Upgraded Safety Buckles: The Upgraded safety buckle provides 5 support points and perfect 40° angle to keep the balance thus avoiding the baby to flip over and fall off. Upgraded into 2 swim ways for perfect Backstroke and Breaststroke. Backstroke Suitable for 3~12 months baby, Breaststroke Suitable for 3~24 months baby

Perfect Fit for Children: Suitable for babies weighing from 13 to 40 lbs. Suitable for Kids 3~24 months. Adjustable buckle at the back to suit most infant sizes. Easily adjustable with the attached Safety pin at the back of the float";echo gtranslate($longtext);

總結(jié)

以上是生活随笔為你收集整理的php调用谷歌翻译接口_PHP调用谷歌翻译的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。