怎么在ThinkPHP中调用百度翻译类实现一个在线翻译功能-创新互联

今天就跟大家聊聊有关怎么在ThinkPHP中调用百度翻译类实现一个在线翻译功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

目前成都创新互联已为上千多家的企业提供了网站建设、域名、网页空间、网站托管、服务器租用、企业网站设计、襄州网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

action代码部分:


display("Public:404"); 
  }
public function index()
{
$User = A("Index"); 
$User->head();
$User->right();
$User->footer();
$this->display();
}
public function fanyi()
{
$value=$_POST['value'];
$from="auto";
$to="auto";
$value_code=urlencode($value); 
$appid="xxxxxxxx";//这里填写你在百度上申请的API key  
$languageurl = "/tupian/20230522/translate
$text=json_decode($this->language_text($languageurl)); 
$text = $text->trans_result; 
$rs=$text[0]->dst;
$this->assign('value',$value);
$this->assign('rs',$rs);
$User = A("Index"); 
$User->head();
$User->right();
$User->footer();
$this->display(index);
}
public function language_text($url) //获取目标URL所打印的内容
{ 
if(!function_exists('file_get_contents')) 
{  
$file_contents = file_get_contents($url); 
} 
else 
{ 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$file_contents = curl_exec($ch); 
curl_close($ch); 
}  
return $file_contents;
}
}
?>

html代码部分:




原文:

{$value}     

译文:

{$rs} 

看完上述内容,你们对怎么在ThinkPHP中调用百度翻译类实现一个在线翻译功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


当前标题:怎么在ThinkPHP中调用百度翻译类实现一个在线翻译功能-创新互联
文章起源:http://scyanting.com/article/csdgeh.html

其他资讯