说明:
一个使用谷歌在线翻译功能将中文汉字转换为E文(英文)的函数。实例应用可以查看这篇文章。
用法:
$productCenterEnName = translate('产品中心'); echo $productCenterEnName; // 输出:Products
代码:
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[0]); return $x[1]; }else{ return false; } } //echo translate('产品中心', 'zh-CN|en');
<完>