欢迎光临
我们一直在努力

ASP利用Google实现在线翻译功能 (2)-ASP教程,ASP技巧

建站超值云服务器,限时71元/月

<html>
<head>
<title>在线翻译</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
<%
on error resume next
 如果网速很慢的话,可以调整以下时间。单位秒
server.scripttimeout = 999999
========================================================
字符编码函数
========================================================
function bytestobstr(body,code) 
dim objstream 
set objstream = server.createobject("adodb.stream") 
objstream.type = 1 
objstream.mode =3 
objstream.open 
objstream.write body 
objstream.position = 0 
objstream.type = 2 
objstream.charset =code
bytestobstr = objstream.readtext 
objstream.close 
set objstream = nothing 
end function 

取行字符串在另一字符串中的出现位置
function newstring(wstr,strng) 
newstring=instr(lcase(wstr),lcase(strng)) 
if newstring<=0 then newstring=len(wstr) 
end function 
替换字符串函数
function replacestr(ori,str1,str2)
replacestr=replace(ori,str1,str2)
end function
=====================================================
function readxml(url,code,start,ends)
set osend=createobject("microsoft.xmlhttp")
sourcecode = osend.open ("get",url,false) 
osend.send()
readxml=bytestobstr(osend.responsebody,code )
if(start="" or ends="") then
else
start=newstring(readxml,start)
readxml=mid(readxml,start)
ends=newstring(readxml,ends)
readxml=left(readxml,ends-1)
end if
end function
dim urlpage,lan
urlpage=request("urls")
lan=request("lan")
%>
<form method="post" action="translate.asp">
<input type="text" name="urls" size="150" value="<%=urlpage%>">
<input type="hidden" name="lan" value="<%=lan%>">
<input type="submit" value="submit">
</form>
<%
dim transurl
transurl="http://216.239.39.104/translate_c?hl=zh-cn&ie
=utf-8&oe=utf-8&langpair="&server.urlencode(lan)&"&u="&urlpage&"
&prev=/language_tools"
if(len(urlpage)>3) then
getcont=readxml(transurl,"gb2312","","")
response.write(getcont)
end if

%>
</body>
</html>

translate.asp实现翻译功能,这是利用google的语言工具实现的。

注意,因为提供多语言支持,所以translate.asp文件所用的编码是支持所有字符的”utf-8″

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP利用Google实现在线翻译功能 (2)-ASP教程,ASP技巧
分享到: 更多 (0)