Randomly add a specific string to the php code at any position in the article

Source: Internet
Author: User
Randomly add a specific string to the php code at any position in the article
Arbitrary position of the article to add a specific string php code, use Tutorial: http://www.tongqiong.com/read.php? Tid-102.html

  1. /* Assume that your text variable is named $ str and the code variable to be inserted is named $ ad [1], $ ad [2], ......
  2. By http://www.tongqiong.com
  3. */
  4. $ Ad [1] = "Tongnan 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. /* You have nothing to say here. what if the text is not 30 characters long? It cannot be inserted between 30-100. So I add a judgment. if it is less than 30, I add it to the end.
  17. By http://www.tongqiong.com
  18. In addition, the article may be longer, such as 10000 characters, but there are only two pieces of code. I will automatically insert code 2 in this writing method, if there is no code 3.
  19. */
  20. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.