Randomly add a specific string of php code anywhere in the article

WBOY
Release: 2016-07-25 09:06:09
Original
1326 people have browsed it
Randomly add a specific string of php code anywhere in the article, usage tutorial: http://www.tongqiong.com/read.php?tid-102.html
  1. /*Assume your text variable is named $str, and the code variables that need to be inserted are named $ad[1], $ad[2], .....
  2. Author: http ://www.tongqiong.com
  3. */
  4. $ad[1]="Tongqiong Forum";
  5. $ad[2]="Where to shop";
  6. $ad[3]="Taizhou Mom Forum";
  7. $ad[4]="Glasses Forum";
  8. $textlength = strlen($str);
  9. $curpos = ($textlength >= 100) ? rand(30, 100) : ($textlength > 30 ? rand( 30, $textlength) :$textlength);
  10. $curadid = 1;
  11. while($curpos < $textlength){
  12. $str = substr($str, 0, $curpos).$ad[$curadid].substr ($str, $curpos, $textlength);
  13. $curpos += rand(20, 50) + strlen($ad[$curadid]);
  14. if($ad[$curadid + 1]) $curadid += 1 ;
  15. }
  16. /*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.
  17. Author: http://www.tongqiong.com
  18. 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.
  19. */
  20. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!