经典ASP(VBScript)的HTML转换codeS为纯文本 [英] Classic ASP (VBScript) convert HTML codes to plain text

查看:271
本文介绍了经典ASP(VBScript)的HTML转换codeS为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想HTML codeS转换像&放大器; #XXXX; (XXXX是一个数字),以纯文本使用传统的ASP(VBScript)的。

I'm trying to convert HTML Codes like the &#XXXX; (where XXXX is a number) to plain text using classic ASP (VBScript).

我添加文本的电子邮件是纯文本格式,如果我将它们添加HTML codeS,它只是显示的code和不转换它们。

I'm adding the text to an email which is in plain text format and if I add them as HTML Codes, it just displays the code and doesn't convert them.

一个解决将是更改电子邮件是HTML它不解决这个问题,但随后引起我的电子邮件其他的问题,我不会去。

One fix would be to change the email to be HTML which does fix that problem but then causes other problems for my email which I won't go into.

有一个内置函数或自定义函数,我可以使用这些HTML codeS转换为纯文本?

Is there a built in function or a custom function I can use to convert these HTML Codes to plain text?

推荐答案

您需要的是HTML德code,但不幸的ASP中不包括的。

What you need is HTML Decode, though unfortunately ASP doesn't include one.

此功能,在 ASP螺母发现,和我重大的修改,应该做你所需要的。我测试了它作为我的本地计算机上运行的VBScript和它似乎运作良好,即使在1000+范围内统一code符号。

This function, found on ASP Nut, and modified heavily by me, should do what you need. I tested it as vbscript running on my local computer and it seemed to work well, even with Unicode symbols in the 1000+ range.

Function HTMLDecode(sText)
    Dim regEx
    Dim matches
    Dim match
    sText = Replace(sText, """, Chr(34))
    sText = Replace(sText, "<"  , Chr(60))
    sText = Replace(sText, ">"  , Chr(62))
    sText = Replace(sText, "&" , Chr(38))
    sText = Replace(sText, " ", Chr(32))


    Set regEx= New RegExp

    With regEx
     .Pattern = "&#(\d+);" 'Match html unicode escapes
     .Global = True
    End With

    Set matches = regEx.Execute(sText)

    'Iterate over matches
    For Each match in matches
        'For each unicode match, replace the whole match, with the ChrW of the digits.

        sText = Replace(sText, match.Value, ChrW(match.SubMatches(0)))
    Next

    HTMLDecode = sText
End Function

<子>注意:你需要在服务器上的脚本5.0版安装使用RegExp对象

这篇关于经典ASP(VBScript)的HTML转换codeS为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆