新闻系统的简单问题

bineon 2003-08-22 08:07:05
如果我给游客开放添加文章的权限,那我怎么避免别人输入html代码呢?
尽量简单的办法
另外这个函数是做什么用的?
<%
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"<"
case ">"
result=result+">"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"""
case "&"
result=result+"&"
case chr(32)
'result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>
...全文
21 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bineon 2003-08-22
  • 打赏
  • 举报
回复
那就是说很又用?
不过现在用了这个函数有如下问题:
我用left()函数读取数据的时候可能出现: ……<br或者出现……<,也就是把htnl读取了一半
那这个问题怎么解决呢?
dufu 2003-08-22
  • 打赏
  • 举报
回复
用这个函数处理用户输入,然后保存进数据库,显示的时候在表格里直接显示,保持以前的段落格式,又不会发生解释html语句的问题。如果修改文章要显示在<textarea>里,则在显示前用下列语句
str=replace(str,"<br>",chr(13))
str=replace(str," "," ")
以保持文章原貌
bineon 2003-08-22
  • 打赏
  • 举报
回复
上面这个函数和server.htmlencode有什么区别?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧