收藏 分销(赏)

显示文本格式的代码.doc

上传人:pc****0 文档编号:6176324 上传时间:2024-11-29 格式:DOC 页数:4 大小:35.50KB 下载积分:10 金币
下载 相关 举报
显示文本格式的代码.doc_第1页
第1页 / 共4页
显示文本格式的代码.doc_第2页
第2页 / 共4页


点击查看更多>>
资源描述
显示文本格式方法代码 点击: 发布日期:2007-8-5 11:14:00 进入论坛 有时大家使用数据库的时候发现插入数据库的一大长篇文章不照你原来的分行。全部挤在一起。那怎么办? <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> function DoWhiteSpace(str) DoWhiteSpace = Replace((Replace(str, vbCrlf, " ")), chr(32)&chr(32), "") End Function </SCRIPT> 上面这一段的代码的意思是把那些空格和回车转换成ASCII码来显示。 上面一段代码随便插哪里都行。 接下来的就是要改下面的代码。在原来的显示代码里加上DoWhiteSpace既可 原来的代码<%=(Recordset1.Fields.Item("msg").value)%> 插入后的代码<%= DoWhiteSpace(Recordset1.Fields.Item("msg").value)%> 显示特殊字符代码。 这一段代码相当重要。有时候做一个留言本的话。如果不使用这段代码的话。那就让人有机可乘了。如果人家输入一段恶意的代码的话,你打开就会执行造成死循环 <%=server.HTMLEncode(scutia.Fields.Item("cont").value)%> 其实就是要server.HTMLEncode这个 自定义文本长度。 有时做留言本。界面设置好了。怕人家的标题太长的话把表撑开怎么办? 有时直接设置只显示多少个字符就行了。但是这样的话,那长的标题就会被切短,人家不知道后面还有内容,很容易造成误会的。 所以我们就想到了在后面加上个。。。 <% Function StrLenB( strString ) dim intLoop,intReturn if isNull(strString) then StrLenB = 0 exit Function end if intReturn = len(strString) for intLoop = 1 to len(strString) if ( asc( mid( strString, intLoop, 1 ) ) < 0 ) then intReturn = intReturn + 1 next StrLenB = intReturn End Function Function strLeftB( strString ,intLen) dim intLenB,intLoop if StrLenB(strString) < intLen then strLeftB = strString exit Function end if for intLoop = 1 to Len(strString) if ( asc( mid( strString, intLoop, 1 ) ) < 0 ) then intLenB = intLenB + 2 else intLenB = intLenB + 1 end if if intLenB > intLen then intLoop = intLoop - 1 exit for elseif intLenB = intLen then exit for end if next strLeftB = left(strString,intLoop) End Function Function IsLetter( chr ) dim blnReturn blnReturn = false if ( ( chr >= asc("a") and chr <= asc("z") ) or ( chr >= asc("A") and chr <= asc("Z") ) or ( chr >= asc("0") and chr <= asc("9") ) ) then blnReturn = true end if IsLetter = blnReturn End Function Function AlignString( string, byVal size ) dim r,nLen,n,i,a,s_i r = string nLen = StrLenB( string ) ' if string's width less then size ,return this string . if ( nLen > size ) then size = size - 2 n = 0 i = 1 ' cut to index do while ( i ) a = asc( mid( string, i, 1 ) ) if ( a < 0 ) then if ( n + 1 = size ) then i = i - 1 exit do end if n = n + 1 end if n = n + 1 if ( n = size ) then exit do i = i + 1 loop 'fxDebug( i ) s_i = i a = asc( mid( string, i+1, 1 ) ) if ( IsLetter(a) ) then do while ( 1 ) a = asc( mid( string, i, 1 ) ) if ( not IsLetter(a) ) then exit do i = i -1 if ( i = 0 ) then i = s_i exit do end if loop end if r = mid( string, 1, i ) & "…" end if AlignString = r End Function %> <% =AlignString((Recordset1.Fields.Item("ID").value), 24) %> 这个代码是经过改良的。主要是修改以前对英文字母的问题, 现在这个是以章字节来算的。就是一个汉字需要2上面的24其实就是24个字母12个汉字来的。 阅读过的文章自动加一 这个是简章的计数器来的。 插件我不知道有没有,但在ud里用command很容易搞定的。 如:文章标题加个连接,用go to detail page行为,传递id参数,在显示文章内容的页面加个command,类型选update,sql如下 update 表 set dianji=dianji+1 where id= 变量 说明:dianji为你的计数字段,变量是要你加的,值为request.querystring("id") 本文来自: 中国自学编程网() 详细出处参考:
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服