在入库之前做一次转换:
HTML标签的转换
<%
Function coder(str)
Dim result,L,i
If IsNull(str) Then : coder="" : Exit Function : End If
L=Len(str) : result=""
For i = 1 to L
select case mid(str,i,1)
case "<" : result=result+"<"
case ">" : result=result+">"
case "&" : result=result+"&"
case chr(9) : result=result+" "
case chr(13) : result=result+"<br/>"
case chr(32) : result=result+" "
case chr(34) : result=result+"""
case chr(39) : result=result+"'"
case else : result=result+mid(str,i,1)
end select
Next
coder=result
End Function
%>Top
2 楼Reve(仨仁仕) 回复于 2003-02-16 12:18:24 得分 10
假如你读出来的字符串是str,那么试一下:
Response.Write("<pre>");
Response.Write(str);
Response.Write("</pre>");
Top
3 楼hchxxzx(NET?摸到一点门槛) 回复于 2003-02-16 14:00:11 得分 10
在入库之前做一次转换:???
这种方法尽量不要用,在读取出来时转换就可以了,写进去的时候尽量保持原文的格式是非常重要的。
下面是一个转换的函数
function my_newline(str)
if str<>"" then
my_newline=replace(str,chr(13)&chr(10),"<br>")
my_newline=replace(my_newline,chr(32)," ")
my_newline=replace(my_newline,chr(9)," ")
else
my_newline=" "
end if
end function
Top
4 楼ruly(若离) 回复于 2003-02-16 14:58:01 得分 20
一个多文本框里输入东西以后再写进数据库,但是在读出来的时候就没有换行了.这个问题产生的原因是:数据库内存储的是你输入的数据的正确形式,而且当数据从数据库中读出后,写入生成的html代码中时,也是你输入时的形式(这一点你可以通过察看html源文件)。但是当ie解析html文件时就忽略了换行等格式。
解决这个问题有两种方法,就是以上各位提出的“<pre></pre>”格式预先定义标识。还有就是进行编码把格式用html标记描述。Top
相关问题