当前位置:asp编程网>技术教程>Asp教程>  正文

将多行区域表单中的内容换成html代码

2007-11-16 18:06:43   来源:本站原创    作者:佚名   浏览量:2988   收藏
开始将多行区域表单中的内容没有处理,就直接保存起来,然后在显示的时候发现,明明保存的时候有换行等格式,但是显示不出来,所有的内容都在一行上。原因是没有将多行区域表单中的内容换成html格式引起这个原因的。
'字符串内容html化
Function inHTML(str)
	Dim sTemp
	sTemp = str
	inHTML = ""
	If IsNull(sTemp) = True Then
		Exit Function
	End If
	'stemp=Replace(stemp, CHR(38), "&")
	sTemp = Replace(sTemp, "&", "&")
	sTemp = Replace(sTemp, "<", "&lt;")
	sTemp = Replace(sTemp, ">", "&gt;")
	stemp=Replace(stemp, CHR(39), "&#39;")
	stemp= Replace(stemp, CHR(32), "&nbsp;")
	sTemp = Replace(sTemp, Chr(34), "&quot;")
	stemp = Replace(stemp, CHR(13), """")
    stemp = Replace(stemp, CHR(10), "<br>")
	inHTML = sTemp
End Function

'将html字符化
Function outHTML(str)
	Dim sTemp
	sTemp = str
	outHTML = ""
	If IsNull(sTemp) = True Then
		Exit Function
	End If 	
	stemp=replace(stemp,"<br>",chr(10))
	stemp=replace(stemp,"""",chr(13))
	stemp=replace(stemp,"&quot;",chr(34))
	stemp=replace(stemp,"&nbsp;",chr(32))
	stemp=replace(stemp,"&#39;",chr(39))
	stemp=replace(stemp,"&gt;",">")
	stemp=replace(stemp,"&lt;","<")
	stemp=replace(stemp,"&amp;","&")
	'stemp=replace(stemp,"&#38;",chr(38))
	outHTML = sTemp	
End Function
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)

用法:
 text=inhtml(request("textarea"))'这样就将textarea中的内容转换成了html代码
 当显示数据库中这个内容到多行表单方法
 <textarea name="textarea" cols="30" rows="30"><%=outhtml(rs("字段名"))%>

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网