html编码不编码空间

时间:2012-11-05 03:38:44

标签: html vbscript encode space

我在vbscript上有以下功能:

Function HTMLEncode(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, ChrW(match.SubMatches(0)), match.Value) 
    Next 

    HTMLEncode = sText 
End Function 

但是,这不会对空间进行编码。当我键入&gt;,&lt;,“,&amp;它们被编码。但是当我输入 space 时它不会被编码。它确实如此,但是当我输入多个空格时它被编码,例如:< / p>

"thishas4spaces    word"

前三个编码除了最后一个空格。所以它是这样的:

"thishas4spaces&nbsp;&nbsp;&nbsp; word"

知道为什么吗?请帮忙。语言是vbscript

0 个答案:

没有答案