标题:[求助]关于显示HTML代码问题
只看楼主
jeanliang
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-9-29
 问题点数:0 回复次数:5 
[求助]关于显示HTML代码问题
我知道如果想在文本框里显示HTML代码就是加server.htmlencode
但是这样话会把空格和换行都转换成HTML
请问有什么方法能显示HTML,又能实现空格和换行的功能呢?急需帮忙,谢谢~~
搜索更多相关主题的帖子: HTML代码 空格 htmlencode server 
2007-11-02 14:56
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 

手工把空格和回车替换回来

2007-11-02 15:07
永夜的极光
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2721
专家分:1
注 册:2007-10-9
得分:0 

你用下面这个函数吧,据说server.htmlencode这个东西安全性还是不高

以下内容来自:http://blog.5d.cn/user7/cnbjx/200507/120605.html


' ============================================
' 通用安全字符串输入,彻底替换server.htmlencode
' ============================================
Function HTMLEncode(Str)
If Isnull(Str) Then
HTMLEncode = \"\"
Exit Function
End If
Str = Replace(Str,Chr(0),\"\", 1, -1, 1)
Str = Replace(Str, \"\"\"\", \""\", 1, -1, 1)
Str = Replace(Str,\"<\",\"&lt;\", 1, -1, 1)
Str = Replace(Str,\">\",\"&gt;\", 1, -1, 1)
Str = Replace(Str, \"script\", \"&#115;cript\", 1, -1, 0)
Str = Replace(Str, \"SCRIPT\", \"&#083;CRIPT\", 1, -1, 0)
Str = Replace(Str, \"Script\", \"&#083;cript\", 1, -1, 0)
Str = Replace(Str, \"script\", \"&#083;cript\", 1, -1, 1)
Str = Replace(Str, \"object\", \"&#111;bject\", 1, -1, 0)
Str = Replace(Str, \"OBJECT\", \"&#079;BJECT\", 1, -1, 0)
Str = Replace(Str, \"Object\", \"&#079;bject\", 1, -1, 0)
Str = Replace(Str, \"object\", \"&#079;bject\", 1, -1, 1)
Str = Replace(Str, \"applet\", \"&#097;pplet\", 1, -1, 0)
Str = Replace(Str, \"APPLET\", \"&#065;PPLET\", 1, -1, 0)
Str = Replace(Str, \"Applet\", \"&#065;pplet\", 1, -1, 0)
Str = Replace(Str, \"applet\", \"&#065;pplet\", 1, -1, 1)
Str = Replace(Str, \"[\", \"&#091;\")
Str = Replace(Str, \"]\", \"&#093;\")
Str = Replace(Str, \"\"\"\", \"\", 1, -1, 1)
Str = Replace(Str, \"=\", \"&#061;\", 1, -1, 1)
Str = Replace(Str, \"'\", \"''\", 1, -1, 1)
Str = Replace(Str, \"select\", \"sel&#101;ct\", 1, -1, 1)
Str = Replace(Str, \"execute\", \"&#101xecute\", 1, -1, 1)
Str = Replace(Str, \"exec\", \"&#101xec\", 1, -1, 1)
Str = Replace(Str, \"join\", \"jo&#105;n\", 1, -1, 1)
Str = Replace(Str, \"union\", \"un&#105;on\", 1, -1, 1)
Str = Replace(Str, \"where\", \"wh&#101;re\", 1, -1, 1)
Str = Replace(Str, \"insert\", \"ins&#101;rt\", 1, -1, 1)
Str = Replace(Str, \"delete\", \"del&#101;te\", 1, -1, 1)
Str = Replace(Str, \"update\", \"up&#100;ate\", 1, -1, 1)
Str = Replace(Str, \"like\", \"lik&#101;\", 1, -1, 1)
Str = Replace(Str, \"drop\", \"dro&#112;\", 1, -1, 1)
Str = Replace(Str, \"create\", \"cr&#101;ate\", 1, -1, 1)
Str = Replace(Str, \"rename\", \"ren&#097;me\", 1, -1, 1)
Str = Replace(Str, \"count\", \"co&#117;nt\", 1, -1, 1)
Str = Replace(Str, \"chr\", \"c&#104;r\", 1, -1, 1)
Str = Replace(Str, \"mid\", \"m&#105;d\", 1, -1, 1)
Str = Replace(Str, \"truncate\", \"trunc&#097;te\", 1, -1, 1)
Str = Replace(Str, \"nchar\", \"nch&#097;r\", 1, -1, 1)
Str = Replace(Str, \"char\", \"ch&#097;r\", 1, -1, 1)
Str = Replace(Str, \"alter\", \"alt&#101;r\", 1, -1, 1)
Str = Replace(Str, \"cast\", \"ca&#115;t\", 1, -1, 1)
Str = Replace(Str, \"exists\", \"e&#120;ists\", 1, -1, 1)
Str = Replace(Str,Chr(13),\"<br>\", 1, -1, 1)
HTMLEncode = Replace(Str,\"'\",\"''\", 1, -1, 1)
End Function


从BFS(Breadth First Study)到DFS(Depth First Study)
2007-11-02 15:31
jeanliang
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-9-29
得分:0 
O_O 谢谢两位!

2007-11-02 15:36
tianyu123
Rank: 1
等 级:新手上路
威 望:2
帖 子:576
专家分:0
注 册:2007-8-26
得分:0 
学习...

改变一切,须从改变观念开始!
2007-11-02 17:43
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 
不用谢
2007-11-02 21:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-182900-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.146184 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved