怎么屏蔽从数据库里读出来html代码
请教各位:
我从数据库里读出来的html代码为什么在网页上原样显示?比如网页上显示成:
<p> 文字 </p>
------解决方案--------------------保存时HTML.Encode
读取时HTML.Decode
------解决方案-------------------- function HtmlToStr(xhtml)
dim tmp,i
for i=1 to len(xhtml)
if mid(xhtml,i,1)= "& " then
tmp=tmp+ "& "
elseif mid(xhtml,i,1)= "# " then tmp=tmp+ "# "
elseif mid(xhtml,i,1)= "; " then tmp=tmp+ "; "
elseif mid(xhtml,i,1)= " " then tmp=tmp+ " "
elseif mid(xhtml,i,1)= " ' " then tmp=tmp+ "' "
elseif mid(xhtml,i,1)= "\ " then tmp=tmp+ "\ "
elseif mid(xhtml,i,1)= " < " then tmp=tmp+ "< "
elseif mid(xhtml,i,1)= "> " then
tmp=tmp+ "> "
else
tmp=tmp+mid(xhtml,i,1)
end if
next
HtmlToStr=replace(tmp,vbcrlf, " <br> ")
end function
Function StrToHTML(xstr)
xstr=replace(xstr, "& ", "& ")
xstr=replace(xstr, "# ", "# ")
xstr=replace(xstr, "; ", "; ")
xstr=replace(xstr, " ", " ")
xstr=replace(xstr, "' ", " ' ")
xstr=replace(xstr, "\ ", "\ ")
xstr=replace(xstr, " <br> ",vbcrlf)
xstr=replace(xstr, "< ", " < ")
xstr=replace(xstr, "> ", "> ")
StrToHTML=xstr
End Function
------解决方案-------------------- '清除HTML标记
Function stripHTML(htmlStr)
Dim regEx
SET regEx = New Regexp
regEx.IgnoreCase = True
regEx.Global = True
'regEx.Pattern = " <.*?> "
regEx.Pattern = " <(.[^> ]*)> "
htmlStr = regEx.Replace(htmlStr, " ")
htmlStr = Replace(htmlStr, " < ", "< ")
htmlStr = Replace(htmlStr, "> ", "> ")
htmlStr = Replace(htmlStr,chr(10), " ")
htmlStr = Replace(htmlStr,chr(13), " ")
stripHTML = Trim(htmlStr)
SET regEx = Nothing
End Function