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

自然之子 2004-04-02 08:56:56
如何将输入的文章原样再显示出来,我知道在保存前用replace把" "用 替换等,但究竟有多少个符号需要转换呢,有谁能帮助提供一个完整的函数?
...全文
62 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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!

28,391

社区成员

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

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