资源描述
显示文本格式方法代码
点击: 发布日期: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")
本文来自: 中国自学编程网() 详细出处参考:
展开阅读全文