中文转英文(基于Google翻译)
还是想用来做seo中的URL路径<?php
function translate($text, $language = 'zh-CN|en'){
if (empty($text))return false;
@set_time_limit(0);
$html = "";
$ch = curl_init("http://google.com/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("</span></span></div></div>", $html);
$x = explode("onmouseout=\"this.style.backgroundColor='#fff'\">", $x);
return $x;
}else{
return false;
}
}
//echo translate('公司介绍', 'zh-CN|en');
页:
[1]