![]() 音乐懒猫
|
Asp 之 向段落末尾添加随机关键字
Asp 之 向段落末尾添加随机关键字
一次在复制别人的东西到自己的网站的时候 偶然发现 复制过来的文章 在段落后面总是有该网站的名称或者别的关键字 这也就罢了 郁闷的是 每刷新一次 关键字的位置都不一样 而且关键中还掺杂了特殊符号 这一下让我郁闷了半天 不过最后也想通了 这样做有好多好处 可以给页面中加入一些随机关键字 关键字中加入随机的特殊符号 这样一来 特殊符号被搜索引擎屏蔽了 但是页面的关键字密度增加了 关键字和特殊符号全是随机的 既优化了页面也给别人复制自己辛辛苦苦整理的东西增加了难度 可谓一举多得呀 于是我按照自己的思路 写了一个这样的向页面中添加随机关键字随机特殊符号的函数 和大家分享一下 函数说明: 此函数的思路为: 把段落按照特殊符号或标记(例如 a div p br )分割成数组,然后计算关键字的位置,重组数组 我的站考虑到有测试代码块信息 所以使用的分割顺序是a div p br 也就是 首先找a 如果没有则找 div 以此类推 以下是代码 其中包含有参数解释 以及 使用方法 主函数名称:HiddenKeyword 辅助函数名称:ReplaceReg和FormatReArray 如果大家想直接看效果可以直接访问我站点任何一个页面 右键查看源代码,正文部分的段落后有随机增加到 “飞飞asp乐园”等字样 复制内容到剪贴板 代码: <% 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 ' 设置是否区分大小写。 regEx.Global=True ReplaceReg = regEx.Replace(str,replStr) ' 作替换。 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 C '-------------------------------------------------------- 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",",|.|。|,|@|!","ff0000")) %> |
![]() |
|
Copyright @ 2004-2021 www.52jdyy.com 激动社区 - 陪你一起慢慢变老!