Randomly add a specific string of php code anywhere in the article, usage tutorial:
http://www.tongqiong.com/read.php?tid-102.html
- /*Assume your text variable is named $str, and the code variables that need to be inserted are named $ad[1], $ad[2], .....
- Author: http ://www.tongqiong.com
- */
- $ad[1]="Tongqiong Forum";
- $ad[2]="Where to shop";
- $ad[3]="Taizhou Mom Forum";
- $ad[4]="Glasses Forum";
- $textlength = strlen($str);
- $curpos = ($textlength >= 100) ? rand(30, 100) : ($textlength > 30 ? rand( 30, $textlength) :$textlength);
- $curadid = 1;
- while($curpos < $textlength){
- $str = substr($str, 0, $curpos).$ad[$curadid].substr ($str, $curpos, $textlength);
- $curpos += rand(20, 50) + strlen($ad[$curadid]);
- if($ad[$curadid + 1]) $curadid += 1 ;
- }
- /*There is something you didn’t mention here. What if the text is not 30 characters long? It's impossible to insert between 30 and 100. So I added a judgment and added it to the end if it was less than 30.
- Author: http://www.tongqiong.com
- In addition, the article may be longer, such as 10,000 characters, but there are only 2 pieces of code. My writing method will automatically insert code 2, if there is no code 3.
- */
- ?>
Copy code
|