把下面代码保存成 get_intro.asp 传到根目录。运行后删除。((如果想导读不为空也自动截取,请把红色去掉。))
本帖在这里发布过。http://bbs.kesion.com/dispbbs.asp?boardid=41&id=39804&star=2&page=1
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Conn.asp"-->
<%'批量取内容的前N个字符做导读
dim strlen '截取的字符数
strlen=200 '默认200个字符(100个汉字)
sql="select ChannelID,ChannelTable,ChannelName from KS_Channel where BasicType=1"
set mors=server.CreateObject("adodb.recordset")
mors.open sql,conn,1,1
if not (mors.bof and mors.eof) then
do while not mors.eof
sql="select Intro,ArticleContent from "&mors(1)&" where TID in(select id from KS_Class where ChannelID="&mors(1)&") and rtrim(Intro)='' or isnull(Intro) "
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,3
if not (rs.bof and rs.eof) then
do while not rs.eof
rs(0)=GotTopic(LoseHtml(replace(rs(1),"[NextPage]","")),strlen)
'如果想去掉所有空格请把上面那句注释用下面这句
'rs(0)=GotTopic(replace(replace(LoseHtml(replace(rs(1),"[NextPage]",""))," ","")," ",""),strlen)
rs.update
rs.movenext
loop
response.write ""&mors(2)&"共批量替换了"&rs.recordcount&"条记录<br>"
else
response.write ""&mors(2)&"没有可替换的内容<br>"
end if
rs.close
set rs=nothing
mors.movenext
loop
response.write "批量替换完成"
else
response.write "没有可替换的内容<br>"
end if
conn.close
set conn=nothing
Function LoseHtml(ContentStr)
On Error Resume Next
Dim TempLoseStr, regEx
If ContentStr="" Or ContentStr=Null Then Exit Function
TempLoseStr = CStr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<\/*[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
TempLoseStr = regEx.Replace(TempLoseStr, "")
LoseHtml = TempLoseStr
End Function
'*************************************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串
' strlen ----截取长度
'返回值:截取后的字符串
'*************************************************************************
Function GotTopic(ByVal Str, ByVal strlen)
If Str = "" OR IsNull(Str) Then GotTopic = "":Exit Function
If strlen=0 Then GotTopic=Str:Exit Function
Dim l, T, c, I, strTemp
Str = Replace(Replace(Replace(Replace(Str, " ", " "), """, Chr(34)), ">", ">"), "<", "<")
l = Len(Str)
T = 0
strTemp = Str
strlen = CLng(strlen)
For I = 1 To l
c = Abs(Asc(Mid(Str, I, 1)))
If c > 255 Then
T = T + 2
Else
T = T + 1
End If
If T >= strlen Then
strTemp = Left(Str, I)
Exit For
End If
Next
If strTemp <> Str Then strTemp = strTemp
GotTopic = Replace(Replace(Replace(Replace(strTemp, " ", " "), Chr(34), """), ">", ">"), "<", "<")
End Function%>
[此贴子已经被作者于2007-12-25 11:03:29编辑过]