This article mainly introduces the implementation method of asp picture-in-picture advertisement insertion in each article. Friends in need can refer to it.
Although many people have given methods to add picture-in-picture advertisements to each article, these so-called methods cannot truly achieve the picture-in-picture effect of text surrounding the advertisement, and can only align left or right. The method to be discussed now can truly achieve the picture-in-picture advertising effect like that of Sina and Sohu.
First, let’s talk about the wrong div+CSS method. I hope you won’t 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 regarded as the effect of left alignment. There are many other methods that are implemented with the help of tables or iframes, and it is nothing more than this.
So, how can we really achieve the effect of adding picture-in-picture ads in batches to each article? It can be done by intercepting fields, there are two pieces of code.
The first paragraph is to analyze the word count of the article content and then insert the code for the advertisement:
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 the intercepted text content RightContent=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. It can also be inserted through table+JS or directly using iframe. Either way, you must set its properties to left-aligned or right-aligned so that it can wrap around 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 'The description 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 greater than the length of the defined substring, determine whether it contains sensitive strings and separate them 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) 'Limited string length exit for else if isascii=1 then x=x+1 end if end if next InterceptString = txtelse InterceptString = end ifEnd Function' Determine the number of times a 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 that grows the static article page (other CMS is similar), insert the first piece of code in front of line 248 HtmlContent = Replace(HtmlContent, {$ArticleContent}, ArticleContent), and add it to the page Insert the second piece of code until appropriate, and then change ArticleContent in that line to ModifyContent.