Although many people have the method of adding image advertisements in each article, these so-called methods cannot truly realize the effect of the text around the advertisement, and can only be aligned left and right. This article is the implementation method of inserting advertisements in Asp into the article. Let’s follow the editor of the Wrong New Technology Channel to learn below!
First, let’s talk about the wrong div+CSS method, and I hope everyone will not be misled:
<div id="outer" style="float:left;"><div id="inner" style="float:left;margin:0;width:200px;height:200px;"></div>Text content</div>
The above can only be considered as a left-aligned effect. There are many things that can be achieved with the help of tables or iframes, which is nothing more than that.
So, how can we truly achieve the effect of batch adding picture-in-picture ads to each article? It can be performed using intercepted fields, with two pieces of code.
The first paragraph analyzes the number of words in the article and then inserts the ad's code:
Dim LeftContent,MidAdContent,RightContent,ModifyContent,headlen,tempStr,headAdStr,tailAdStr'''Intercept the appropriate number of strings if len(ArticleContent)<320 then headlen=200else headlen=320end iftempStr=ArticleContentLeftContent=InterceptString(tempStr,headlen)'Get intercepted text contentRightContent=Right(ArticleContent,Len(ArticleContent)-Len(LeftContent))ModifyContent=LeftContent &"<div style=""float:left;""><script language=""javascript"" src=""http://www.eryi.org/ad.js""></script></div>"& RightContent
The above is to insert ads through DIV+JS. The ad code is placed in the ad.js file, or it can be inserted through table+JS or directly using iframe. In either way, its properties must be set to left-aligned or right-aligned so that it can be guaranteed to surround the ad.
The next second paragraph is the judgment of the picture-in-picture advertising code.
Function InterceptString(txt,length)Dim x,y,ii,c,ischines,isascii,tempStrtxt=trim(txt)x = len(txt)y = 0if x >= 1 then for ii = 1 to xc=asc(mid(txt,ii,1))if c< 0 or c >255 then 'Explanation is a Chinese character y = y + 2 ischines=1 isascii=0else 'Explanation is an ascii code y = y + 1 ischines=0 isascii=1end if'If the length is already greater than the length of the defined substring, determine whether it contains sensitive strings and is separated if y >= length then if ischines=1 and StrCount(left(trim(txt),ii),"<a")=StrCount(left(trim(txt),ii),"</a>") then txt = left(trim(txt),ii) '" string limit exit for else if isascii=1 then x=x+1 end if end if next InterceptString = txtelse InterceptString = ""end ifEnd Function'Judge the number of times the string appears Function StrCount(Str,SubStr) Dim iStrCount Dim iStrStart Dim iTemp iStrCount = 0 iStrStart = 1 iTemp = 0 Str=LCase(Str) SubStr=LCase(SubStr) Do While iStrStart < Len(Str) iTemp = Instr(iStrStart,Str,SubStr,vbTextCompare) If iTemp <=0 Then iStrStart = Len(Str) Else iStrStart = iTemp + Len(SubStr) iStrCount = iStrCount + 1 End If Loop StrCount = iStrCountEnd Function
Take the new cloud website management system as an example. First find the code file /inc/NewsChannel.asp (other CMSs are similar to this), insert the first piece of code in front of HtmlContent = Replace(HtmlContent, "{$ArticleContent}", ArticleContent) on line 248, insert the second piece of code until appropriate in the page, and then change the ArticleContent in that line to ModifyContent.
The above is the implementation method of inserting advertisements in Asp into the article. I hope that after understanding the introduction of this article, everyone will have a certain understanding, and I hope that everyone will continue to support the wrong new technology channel!