设为首页
收藏本站
最新电影
> 子栏目 Asp | Jsp | XML | XSL | Div+Css | 自定义函数 | 数据库 | 脚本特效
您现在的位置: 首页=>后台技术=>自定义函数 订阅本栏目  
给文章段落添加随机隐藏关键字
时间: 2007-10-06 16:40:15 阅读次数:2403


以下是代码片段:
<%
function FormatReArray(str)
 dim temp,sindex,temp1
 temp=str&","
 temp1=split(temp,",")
 for sindex=0 to ubound(temp1)
  if temp1(sindex)<>"" then
   temp=replace(temp,temp1(sindex)&",","")
   temp=temp&temp1(sindex)&","
  end if
 next
 FormatReArray=left(temp,len(temp)-1)
end function

Function ReplaceReg(str,patrn,replStr,Ignor)
'=========================================
'参数解释:
'str      原来的字符串
'patrn    要替换的字符串(正则表达式)
'replStr  要替换成的字符串
'Ignor    是否区分大小写(1不区分,0区分)
'=========================================
  Dim regEx                      ' 建立变量
  If Ignor=1 Then Ignor=true else Ignor=false
  Set regEx = New RegExp               ' 建立正则表达式
  regEx.Pattern = "("&patrn&")"               ' 设置模式
  regEx.IgnoreCase = Ignor               ' 设置是否区分大小写飞飞Asp技术乐园
  regEx.Global=True
  ReplaceReg = regEx.Replace(str,replStr)         ' 作替换飞飞As,p技术乐园
End Function


Function HiddenKeyword(Content,RndKeyWordCount,AllKeyword,AllSign,HiddenColor)
'********************************************
'作者:飞飞
'QQ:276230416
'网址:www.ffasp.com
'邮箱:huanmie913@163.com
'********************************************
'函数使用参数说明
'Content:            需要执行添加隐藏关键字的文字、段落、文章
'RndKeyWordCount:    添加隐藏关键字的个数
'AllKeyword:         要添加到文章中的文字【要向段落末尾添加的关键字,多关键字请使用"|"分割】
'AllSign             添加到关键字中特殊符号【向关键字中添加随机特殊符号,多特殊符号请使用"|"分割,特殊符号请勿使用"|"】
'HiddenColor:        要添加到文章中的文字的颜色(和背景色相同,达到隐藏的目的)
'*********************************************
'使用的外部函数有 
'1.ReplaceReg     [正则表达式替换关键字]
'2.FormatReArray  [去除数组中的重复项]
'*********************************************
'使用实例:
'Response.Write(HiddenKeyword("aaaaaaaaaaaa<br />bbbbbbbbbbb<br>ccccccccc<br>ddddddddd<br>eeeeeeeeeeeee",3,"飞飞Asp乐园|ffasp",",|.||,|@|!","ff0000"))
'请查看源代码查看效果
'
'*********************************************
Dim EContent,UboundEContent,RndKeyWordArray,DomainLength,DomainPoint,TagName
Dim Keyword,ArryKeyword,ArryCountKeyword,KeywordLength,ArryUboundKeyword
Dim Sign,ArrySign,ArryUboundsign,SignLength
'------------------------------------------------------
Content=ReplaceReg(Content,"<br>","<br />",1)
Content=ReplaceReg(Content,"<br/>","<br />",1)
Content=ReplaceReg(Content,"</div>","</div>",1)
Content=ReplaceReg(Content,"</p>","</p>",1)
Content=ReplaceReg(Content,"</a>","</a>",1)
'-------------------------------------------------------
If instr(Content,"</a>")>0 Then 
 TagName="</a>"
ElseIf   instr(Content,"</div>")>0 Then
 TagName="</div>"
ElseIf instr(Content,"</p>")>0 Then 
 TagName="</p>"
ElseIf instr(Content,"<br />") Then
 TagName="<br />"
Else 
 TagName="</a>"
End If  
Randomize
'-------------------------------------------------------
RndKeyWordArray=""
EContent=split(Content,TagName)
UboundEContent=Ubound(EContent)
If UboundEContent+1-RndKeyWordCount<0 Then RndKeyWordCount=UboundEContent+1
Content=""
'--------------------------------------------------------
for i=1 to RndKeyWordCount
RndKeyWordArray=RndKeyWordArray&Int((UboundEContent+1) * Rnd)
If i<>RndKeyWordCount Then RndKeyWordArray=RndKeyWordArray&","
next
RndKeyWordArray=","&FormatReArray(RndKeyWordArray)&","
for i=0 to UboundEContent
'=====取出关键字========================== 
 ArryKeyword=split(AllKeyword,"|")
 ArryUboundKeyword=Ubound(ArryKeyword)
 Keyword=ArryKeyword(int((ArryUboundKeyword+1)*Rnd))
 KeywordLength=len(Keyword)
'=====取出特殊符号========================
 ArrySign=Split(AllSign,"|")
 ArryUboundSign=Ubound(ArrySign)
 Sign=ArrySign(int((ArryUboundSign+1)*Rnd))
'========================================= 
 Content=Content&EContent(i)
 If i<>UboundEContent Then Content=Content&TagName
 If instr(RndKeyWordArray,","&i&",")>0 and i<>UboundEContent Then 
  DomainPoint=Int((KeywordLength) * Rnd + 1) 
  If DomainPoint=KeywordLength  Then sign=""
  Content=Content&"<span style=""color:#"&HiddenColor&";display:none"">"&left(Keyword,DomainPoint)&sign&mid(Keyword,DomainPoint+1)&"</span>"
 End If 
Next
'--------------------------------------------------------
HiddenKeyword=Content
End Function

Response.Write(HiddenKeyword("aaaaaaaaaaaa<br />bbbbbbbbbbb<br>ccccccccc<br>ddddddddd<br>eeeeeeeeeeeee",3,"飞飞Asp乐园|ffasp",",|.|飞飞Asp技术乐园|,|@|!","ff0000"))
%>




站内搜索    

下一篇利用FSO向文件写内容

上一篇获取字符串实际占用字节数(如何取特定的长)(len)

本栏目最新 栏目最新列表
解决asp使用xmlhttp生成静态页有延时的方法
Asp按照指定目录使用fso创建文件夹
使用aspjpeg组件给指定图片添加文字水印
使用aspjpeg组件给指定图片添加图片水印
使用aspjpeg组件生成缩略图
网站优化策划 栏目最新列表
增加网站外链的快速方法
网站上线前必做的30个检查
新的友情链接参考标准(没有google的PR情况
优化Google的AdSense广告的五个工具
王通讲SEO八大基础
站点最新 站点最新列表
微博推广的一些技巧
xhEditor v1.1.7 发布,
收集的一些轻量级非常实
50个新鲜兼容最新版本的
javascript中cookie的设
Excel中出现#VALUE!、#D
jquery插件:飞飞表情插件
十个使用HTML5开发的精彩
支持HTML5的浏览器有哪些
飞妮莫属:漫画:如何写出
历史最热10条信息  
MIME介绍 及 [1] [2] [3]
巧用Google和迅雷来下载
Transact SQL 常 [1] [2]
VIA Rhine II Fast Ethe
电脑常用端 [1] [2] [3]
Do you get a kick out
十道羊皮卷 欣赏+mp3版+
每日一句:A friend and
每日一句:Theres no tu
经典__悟透JavaScript
 width= 
伟哥博客 西安房产 123最新电影 三四六四