ASP漢字轉(zhuǎn)拼音,支持自定義特殊詞語(yǔ)_ASP教程
推薦:ASP連接11種數(shù)據(jù)庫(kù)語(yǔ)法總結(jié)經(jīng)常使用到有關(guān)數(shù)據(jù)庫(kù)的操作。包括連接代碼、SQL命令等等,又不曾刻意去記憶它們(我本人是不愿意去記這東東),所以常常在用到的時(shí)候又去查書(shū)本,翻來(lái)翻去。一些比較少用的數(shù)據(jù)庫(kù)還不一定能順
這次更新了一下自已所用的博客程序,將生成靜態(tài)文件時(shí)的文件名用文章標(biāo)題的拼音,這就涉及到如何將文字轉(zhuǎn)成拼音了,在網(wǎng)上大概的看了看,千篇一律的那個(gè)函數(shù),應(yīng)該只可以在GB2312下正常,也沒(méi)有做太多考慮,這就拿出了曾在無(wú)憂(yōu)系統(tǒng)的源碼里看到過(guò)的一段用上了。
來(lái)看看下面的函數(shù),加入少量注釋?zhuān)?br />
這是一個(gè)自定義特殊詞語(yǔ)的一個(gè)函數(shù)
| 以下為引用的內(nèi)容: Function getEnglish(ByVal Str) getEnglish = Str getEnglish = Replace(getEnglish, "中國(guó)", " china ") getEnglish = Replace(getEnglish, "策劃", " plan ") getEnglish = Replace(getEnglish, "免費(fèi)", " free ") getEnglish = Replace(getEnglish, "介紹", " intro ") getEnglish = Replace(getEnglish, "技巧", " skill ") getEnglish = Replace(getEnglish, "生活", " life ") getEnglish = Replace(getEnglish, "活動(dòng)", " activity ") getEnglish = Replace(getEnglish, "工具", " tool ") getEnglish = Replace(getEnglish, "聯(lián)盟", " union ") getEnglish = Replace(getEnglish, "注冊(cè)", " register ") getEnglish = Replace(getEnglish, "經(jīng)驗(yàn)", " experience ") getEnglish = Replace(getEnglish, "翻譯", " translate ") getEnglish = Replace(getEnglish, "項(xiàng)目", " item ") getEnglish = Replace(getEnglish, "網(wǎng)站", " web-site ") getEnglish = Replace(getEnglish, "英語(yǔ)", " english ") getEnglish = Replace(getEnglish, "英文", " english ") getEnglish = Replace(getEnglish, "雅虎", " yahoo ") getEnglish = Replace(getEnglish, "新浪", " sina ") getEnglish = Replace(getEnglish, "支付寶", " alipay ") getEnglish = Replace(getEnglish, "交易", " trade ") getEnglish = Replace(getEnglish, "網(wǎng)店", " b2c ") getEnglish = Replace(getEnglish, "升級(jí)", " update ") getEnglish = Replace(getEnglish, "雜志", " magazine ") getEnglish = Replace(getEnglish, "空間", " space ") getEnglish = Replace(getEnglish, "愛(ài)情", " love ") getEnglish = Replace(getEnglish, "朋友", " friend ") getEnglish = Replace(getEnglish, "友情", " friend ") getEnglish = Replace(getEnglish, "鏈接", " like ") getEnglish = Replace(getEnglish, "標(biāo)簽", " label ") getEnglish = Replace(getEnglish, "運(yùn)行", " running ") getEnglish = Replace(getEnglish, "管理", " manager ") getEnglish = Replace(getEnglish, "管理", " manage ") getEnglish = Replace(getEnglish, "頁(yè)面", " page ") getEnglish = Replace(getEnglish, "模板", " template ") getEnglish = Replace(getEnglish, "游戲", " game ") getEnglish = Replace(getEnglish, "論壇", " forum ") getEnglish = Replace(getEnglish, "新聞", " news ") getEnglish = Replace(getEnglish, "音樂(lè)", " music ") getEnglish = Replace(getEnglish, "幫助", " help ") getEnglish = Replace(getEnglish, "優(yōu)化", " optimize ") getEnglish = Replace(getEnglish, "軟件", " soft ") getEnglish = Replace(getEnglish, "教程", " tech ") getEnglish = Replace(getEnglish, "下載", " download ") getEnglish = Replace(getEnglish, "搜索", " search ") getEnglish = Replace(getEnglish, "引擎", " engine ") getEnglish = Replace(getEnglish, "蜘蛛", " spider ") getEnglish = Replace(getEnglish, "日志", " log ") getEnglish = Replace(getEnglish, "博客", " blog ") getEnglish = Replace(getEnglish, "百度", " baidu ") getEnglish = Replace(getEnglish, "谷歌", " google ") getEnglish = Replace(getEnglish, "郵箱", " mailbox ") getEnglish = Replace(getEnglish, "郵件", " mail ") getEnglish = Replace(getEnglish, "域名", " domain ") getEnglish = Replace(getEnglish, "測(cè)試", " test") getEnglish = Replace(getEnglish, "演示", " demo ") getEnglish = Replace(getEnglish, "音樂(lè)", " music ") getEnglish = Replace(getEnglish, "笑話(huà)", " joke ") getEnglish = Replace(getEnglish, "產(chǎn)品", " product ") getEnglish = Replace(getEnglish, "留言", " message ") getEnglish = Replace(getEnglish, "反饋", " freedback ") getEnglish = Replace(getEnglish, "評(píng)論", " comment ") getEnglish = Replace(getEnglish, "推薦", " commend ") getEnglish = Replace(getEnglish, "共享", " share ") getEnglish = Replace(getEnglish, "資源", " resource ") getEnglish = Replace(getEnglish, "插件", " plugins ") getEnglish = Replace(getEnglish, "本本", " notebook ") getEnglish = Replace(getEnglish, "電腦", " computer ") getEnglish = Replace(getEnglish, "系統(tǒng)", " system ") getEnglish = Replace(getEnglish, "學(xué)校", " school ") getEnglish = Replace(getEnglish, "無(wú)憂(yōu)", " 5u ") getEnglish = Replace(getEnglish, "工作", " job ") getEnglish = Replace(getEnglish, "信息", " info ") getEnglish = Replace(getEnglish, "娛樂(lè)", " ent ") getEnglish = Replace(getEnglish, "汽車(chē)", " car ") getEnglish = Replace(getEnglish, "手機(jī)", " mobile ") getEnglish = Replace(getEnglish, "網(wǎng)絡(luò)", " network ") getEnglish = Replace(getEnglish, "老板", " boss ") getEnglish = Replace(getEnglish, "狗", " dog ") getEnglish = Replace(getEnglish, "電視", " tv ") getEnglish = Replace(getEnglish, "電影", " movie ") End Function |
然后就是最關(guān)鍵的函數(shù)pinyin(byval chinese) 他將中文轉(zhuǎn)換到拼音
| 以下為引用的內(nèi)容: function pinyin(byval chinese) chinese = replace(chinese, "/", ""): chinese = replace(chinese, "\", "") chinese = replace(chinese, "*", ""): chinese = replace(chinese, "]", "") chinese = replace(chinese, "[", ""): chinese = replace(chinese, "}", "") chinese = replace(chinese, "{", ""): chinese = replace(chinese, "'", "") chinese = getEnglish(chinese) '在這里使用getEnglish先將特殊詞語(yǔ)轉(zhuǎn)換 dim pinyinstr, istr, iIsCn, IsCn dim pinyinconn, rs, i, x '在這里打開(kāi)拼音庫(kù) '你也可以將拼音庫(kù)的并入你的程序數(shù)據(jù)庫(kù)里. on error resume next set pinyinconn = server.createobject("Adodb.connection") pinyinconn.open "Provider=Microsoft.Jet.OLEdb.4.0;Data Source=" & server.mappath("pinyin.Asp") if err then pinyin = "": set pinyinconn = nothing: exit function IsCn = true for i = 1 to len(chinese) iIsCn = IsCn ' 獲取上次是不是中文的值 istr = Mid(chinese, i, 1) x = Asc(istr) if (x >= 65 and x <= 90) or (x >= 97 and x <= 122) or (x >= 48 and x <= 57) or istr = " " then IsCn = false ' 這些是英文,數(shù)字(保留字符),不改動(dòng) if istr = " " then istr = "-" else set rs = pinyinconn.execute("select Top 1 [pinyin] From [pinyin] Where [content] like '%" & istr & "%';") if not rs.eof then istr = lcase(rs(0)): IsCn = true ' 中文 else IsCn = false if istr = " " then istr = "-" else istr = "" ' 將空格轉(zhuǎn)換成-,如果是其他字符則清除 end if rs.close: set rs = nothing end if if iIsCn = IsCn then pinyinstr = pinyinstr & istr else pinyinstr = pinyinstr & "-" & istr pinyinstr = replace(pinyinstr, "--", "-") pinyinstr = replace(pinyinstr, "__", "_") next if right(pinyinstr, 1) = "-" then pinyinstr = left(pinyinstr, len(pinyinstr) - 1) if right(pinyinstr, 1) = "_" then pinyinstr = left(pinyinstr, len(pinyinstr) - 1) if left(pinyinstr, 1) = "-" then pinyinstr = right(pinyinstr, len(pinyinstr) - 1) if left(pinyinstr, 1) = "_" then pinyinstr = right(pinyinstr, len(pinyinstr) - 1) pinyinconn.close set pinyinconn = nothing pinyin = trim(pinyinstr) end Function |
使用方法:
| 以下為引用的內(nèi)容: response.write pinyin("中國(guó)你好,歡迎來(lái)到中國(guó)!") |
這種方法,轉(zhuǎn)換成的拼音格式文件名非常友好,對(duì)SEO方面有要求的小程們,可以試試的。
分享:asp簡(jiǎn)介和五大內(nèi)置對(duì)象目次 1.ASP基礎(chǔ) 2.ASP的五大對(duì)象 3.Request對(duì)象 4.Response對(duì)象 5.Server對(duì)象 6.Application對(duì)象 7.Session對(duì)象 1.ASP基礎(chǔ) Microsoft Active Server Pages,即讀者朋友們所稱(chēng)的
- asp FSO 讀寫(xiě)文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶(hù)真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- 用Asp隱藏文件路徑,實(shí)現(xiàn)防盜鏈
- 設(shè)置IIS中某個(gè)目錄禁止執(zhí)行ASP程序方法
- ASP調(diào)用純真IP庫(kù)實(shí)例
- 怎樣使ASP分頁(yè)顯示Recordset數(shù)據(jù)
- ASP常用代碼剪輯
- asp中提示至少一個(gè)參數(shù)沒(méi)有被指定值 解決方法
- ASP+Access的安全隱患以及解決方法
- Cookies 欺騙漏洞的防范(vbs js 實(shí)現(xiàn))
- 關(guān)于學(xué)習(xí)ASP和編程的28個(gè)觀(guān)點(diǎn)
- Asp三級(jí)聯(lián)動(dòng)下拉菜單數(shù)據(jù)庫(kù)版(含源程序)
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-ASP漢字轉(zhuǎn)拼音,支持自定義特殊詞語(yǔ)
。