如何将输入的文章原样再显示出来?

自然之子 总经理  2004-04-02 08:56:56
如何将输入的文章原样再显示出来,我知道在保存前用replace把" "用 替换等,但究竟有多少个符号需要转换呢,有谁能帮助提供一个完整的函数?
...全文
30 点赞 收藏 17
写回复
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
自然之子 2004-04-02
已经搞定,谢谢各位!
回复
possible_Y 2004-04-02
可以在取出时转换
Response.Write Replace(Replace(rs("content"),chr(13)&chr(10),"<br>")," "," ")
回复
自然之子 2004-04-02
是不是还应该有个在存入数据库时的转换函数?
回复
jiffer 2004-04-02
Function HTMLEncode(fString)
If Not IsNull(fString) Then
Dim bwords,ii
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")

fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

End Function
回复
webdevelop 2004-04-02
<%
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
%>
回复
hglwy 2004-04-02
你试试我这个函数

'HTML转换函数
function htmlencode(str)
on error resume next
dim result
dim l
if isnull(str) then
htmlencode=""
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 chr(13)
result=result+"<br>"
case chr(9)
result=result+"    "
case chr(32)
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 else
result=result+mid(str,i,1)
end select
next
if err.number<>0 then err.clear
htmlencode=result
end function

%>
回复
qxg1123 2004-04-02
Function HTMLEncode(fString)
IF not isnull(fString) then
fString = Replace(fString, ">", ">")
fString = Replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(10) & CHR(13), "<br> ")
HTMLEncode = fString
End IF
End Function
回复
自然之子 2004-04-02
可是在我这里,用了上面几位的办法,都不行,不过我在存入数据库的时候没有做任何转换.
回复
自然之子 2004-04-02
我再测试一下,就是这样的:
Function HTMLEncode(fString)
IF not isnull(fString) then
fString = Replace(fString, ">", ">")
fString = Replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLEncode = fString
End IF
End Function
用这个函数
<%=HtmlEncode(Content)%>
回复
自然之子 2004-04-02
我要的就是象FlashFK()这样的显示效果
回复
a_zhe_20 2004-04-02
都说的差不多了。
基本上是把换行和空格替换成浏览器可识别的HTML代码就可以了。
换行<p><br>
空格 
回复
yishanjushi 2004-04-02
最好还是在插入数据时原本原本插入数据库中不要替换,显示的时候转换一下再显示出来。
回复
paz 2004-04-02
<%
Dim strCont
strCont=(Recordset1.Fields.Item("内容").Value)
strCont=Replace(strCont,vbCrLf,"<br>   "&vbCrLf)
Response.write strCont
%>

<%
Dim strCont
strCont=Rs("contents")
strCont=Replace(strCont,vbCrLf,"<br>   "&vbCrLf)
Response.write strCont
%>
回复
zhfkhx 2004-04-02
下几套新闻提交系统,仔细研究一下,推荐沸腾的
回复
FlashK 2004-04-02
Function HTMLEncode(fString)
IF not isnull(fString) then
fString = Replace(fString, ">", ">")
fString = Replace(fString, "<", "<")
fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
HTMLEncode = fString
End IF
End Function
用这个函数
<%=HtmlEncode(Content)%>
回复
fkphp 2004-04-02
strInputEntry = Replace(strInputEntry, "&", "&", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "<", "<", 1, -1, 1)
strInputEntry = Replace(strInputEntry, ">", ">", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "[", "[")
strInputEntry = Replace(strInputEntry, "]", "]")
strInputEntry = Replace(strInputEntry, """", "", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "=", "=", 1, -1, 1)
strInputEntry = Replace(strInputEntry, "'", "''", 1, -1, 1)
回复
flying310 2004-04-02
Replace()
  FUNCTION: Returns a string in which a specified sub-string has been replaced with another substring a specified number of times.
  SYNTAX: Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [, compare]]])
  ARGUMENTS: strToBeSearched is a string expression containing a sub-string to be replaced; strSearchFor is the string expression to search for within strToBeSearched; strReplaceWith is the string expression to replace sub-string strSearchFor; start (optional) is the numeric character position to begin search; count (optional) is a value indicating the comparision constant.
  EXAMPLE: <%
  strTest = "This is an apple!"
  response.write Replace(strTest, "apple", "orange")
  %>
  RESULT: This is an orange!
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告