您的位置:首页 > Web前端 > HTML

2006-5-22 文本 转 HTML 与 HTML 转 文本 操作记录小结 By Stabx

2006-05-23 10:18 489 查看
标题: 文本 转 HTML 与 HTML 转 文本 操作记录小结 By Stabx正文:文本与HTML 之间的互转, 主要是在添加更新数据与读取数据时用到.添加数据与更新数据用 文本 转 HTML;读取数据用 HTML 转 文本.表单 ttextarea 在读取数据时自动解码HTML字符, 有时对某些特定字符我们并不要这样, 这就需要HTML 转文本.首先, 我需要的不是单纯的 文本 与 HTML 之间的互转, 加入了 UBB 开关选项, 加入了 HTML 开关选项, 2*2=4, 这需要四个判断. 文本 转 HTML 1. 在输入了类似于 URL 地址栏之类的地址, 要求自动转为 URL 链接2. 在输入了类似电子邮件之类的地址, 要求自动转为 EMAIL 链接.3. 在输入了 UBB 标签时要求转换为相对的 HTML 标签.4. 换行符,空格符,跳格符 的格式都要保留, 这也许制造了不少垃圾, 但这比较以人为本, 为何要将就机器来着, 机器应该将就人. 注: 文本与HTML互转 共用了五个函数来执行操作//并用 ACCESS 的 是/否 数据类型来判断开关添加更新数据时1. textToHtml 主函数, 执行了转换HTML,转换UBB的功能2. textToHtmlNullUBB 函数, 在 UBB 关, HTML 开时使用该函数3. textToHtml1 在 UBB 与 HTML 都关时, 使用改函数读取数据时4. textToHtmlNullUBB1 在读取数据时使用该函数, 并且 UBB 关 HTML开时 和 UBB HTML 都关时, 使用该函数5. htmlToText 主函数, 在 读取数据时使用该函数, 并且 UBB 开 HTML开时 和 UBB 开 HTML 关时, 使用改函数shawl.qiu2006-5-22
添加或更新数据时: 文本 转 HTML | UBB 开关 与 HTML 开关相关逻辑 
 
                title_=request.Form("title")                 content_=request.Form("content")
        if     htmloff_=1 and ubboff_=1  then 'html 和 ubb 都关闭则                 title_=textToHtml1(trim(title_))                 content_=textToHtml1(content_)         end if         if     htmloff_=0 and ubboff_=0  then 'html 和 ubb 都开启则                 title_=textToHtml(trim(title_))                 content_=textToHtml(content_)         end if         if htmloff_=0 and ubboff_=1 then 'HTML 开, UBB 关                 title_=textToHtmlNullUBB(trim(title_))                  content_=textToHtmlNullUBB(content_)         end if         if htmloff_=1 and ubboff_=0 then 'HTML 关, UBB 开                 title_=textToHtml(trim(title_))                 content_=textToHtml(content_)         end if 
读取数据时:HTML 转 文本 | UBB 开关 与 HTML 开关相关逻辑              htmloff_=rs("htmloff")             ubboff_=rs("ubboff")             tt_=rs("title")             ct_=rs("content")     if     htmloff_=true and ubboff_=true  then 'UBB HTML 都关闭             tt_=tt_              ct_=textToHtmlNullUBB1(ct_)     end if     if     htmloff_=false and ubboff_=false  then  'UBB HTML 都开启             tt_=htmlToText(tt_)             ct_=htmlToText(ct_)     end if     if     ubboff_=true and htmloff_=false then 'UBB关, HTML 开             tt_=htmlToText(tt_)             ct_=htmlToText(ct_)     end if     if     ubboff_=false and htmloff_=true then 'UBB 开, HTML 关             tt_=textToHtmlNullUBB1(tt_)             ct_=textToHtmlNullUBB1(ct_)     end if
 
  文本 与 HTML 互转文件<%'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' subject    : 文本 转 HTML 与 HTML 转 文本 函数 By shawl.qiu'' writer    : Stabx<shawl.qiu@gmail.com>'' blog        : http://blog.csdn.net/btbtd / http://btbtd.exblog.jp/ '' blog/site    : Phoenix.GI - P.GI / / 绿色学院 - Green Institute'' date        : 2006-5-22'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''function textToHtml(str)     dim re     if isNULL(str) then     textToHtml=""     exit function     end if         'str=replace(str,"&","&")         str=replace(str,"/","\")         str=replace(str,"'","'")         str=replace(str,chr(34),""")         str=replace(str,chr(32),"  ")         str=replace(str,"<","<")         str=replace(str,">",">")         str=replace(str,chr(13),"")         str=replace(str,chr(9),"    ")         str=replace(str,"ttextarea","ttextarea")         str=replace(str,"
","[code]",1,-1,1)         str=replace(str,"
","[/code]",1,-1,1)         str=replace(str,"[cite]","[cite]",1,-1,1)         str=replace(str,"[/cite]","[/cite]")         str=replace(str,"
","[quote]",1,-1,1)         str=replace(str,"
","[/quote]",1,-1,1)     Set re = New RegExp         re.Global = true         re.IgnoreCase = true        re.Pattern = "/[email/](.*)/[//email/]"         str = re.Replace(str,"http://blog.csdn.net/btbtd/article/details/$1")         '[email]shawl.qiu@gmail.com[/email]                 re.Pattern = "/[img/](.+)/[//img/]"         str = re.Replace(str,"<img width=200 src=http://http://blog.csdn.net/btbtd/article/details/$1></img>")                             re.Pattern = "((http/:////)|())([/w-]+/.+[/w-/.]+/.+[a-zA-Z0-9]+)(/:+[0-9]+/[/w-./?_%=&]*|/[/w-./?_%=&]*)?"         str = re.Replace(str,"$2$3$4$5")                 re.Pattern = "/[url/](.*?)/[//url/]"         str = re.Replace(str,"http://blog.csdn.net/btbtd/article/details/$1")        re.Pattern = "(([/w-]+/@+)|([/w-]+/.+[/w-]+/@+))(([/w-]+/.)([/w-]+/.)([a-zA-Z]+)|([/w-]+/.)([a-zA-Z]+))"         str = re.Replace(str,"[email]$2$3$4[/email]")                 str=replace(str,"  "," ")             textToHtml=strend function'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''文本 转 HTML 函数 不加 UBBfunction textToHtmlNullUBB(str)     dim re     if isNULL(str) then     textToHtmlNullUBB=""     exit function     end if         str=replace(str,"&","&")         str=replace(str,"'","'")         str=replace(str,chr(34),""")         str=replace(str,"<","<")         str=replace(str,">",">")         str=replace(str,chr(13),"")         str=replace(str,chr(9),"    ")         str=replace(str,"ttextarea","ttextarea")     textToHtmlNullUBB=strend function'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''文本转 HTML 1function textToHtml1(str)     if     str="" then         exit function     end if         str=replace(str,"'","'")         str=replace(str,"  "," ")         str=replace(str,"ttextarea","ttextarea")     textToHtml1=Strend function'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''文本 转 HTML 函数 不加 UBBfunction textToHtmlNullUBB1(str)     dim re     if isNULL(str) then     textToHtmlNullUBB=""     exit function     end if         str=replace(str,"&","&")         str=replace(str,"'","'")         str=replace(str,chr(34),""")         str=replace(str,"<","<")         str=replace(str,">",">")         str=replace(str,chr(9),"    ")         str=replace(str,"ttextarea","ttextarea")     textToHtmlNullUBB1=strend function'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''HTML 转 文本function htmlToText(str)     Dim re     if     str="" then         exit function     end if         str=replace(str,"<","<")         str=replace(str,">",">")         str=replace(str,"ttextarea","ttextarea")         str=replace(str,"
","[code]",1,-1,1)         str=replace(str,"
","[/code]",1,-1,1)         str=replace(str,"[cite]","[cite]",1,-1,1)         str=replace(str,"[/cite]","[/cite]",1,-1,1)         str=replace(str,"
","[quote]",1,-1,1)         str=replace(str,"
","[/quote]",1,-1,1)         str=replace(str,"",chr(13),1,-1,1)    Set re = New RegExp         re.Global = true         re.IgnoreCase = true        re.Pattern = "<a.*?href=mailto/:.*?/>(.*?)/<//a/>"         Str = re.Replace(Str,"[email]http://blog.csdn.net/btbtd/article/details/$1[/email]")                 re.Pattern = "<img.*?src=/:.*?/>(.*?)/<//img/>"         Str = re.Replace(Str,"")        re.Pattern = "<a.*?href=http.*?/>(.*?)/<//a/>"         Str = re.Replace(Str,"http://blog.csdn.net/btbtd/article/details/$1")             htmlToText=Strend function%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息