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
- /* Assume that your text variable is named $ str and the code variable to be inserted is named $ ad [1], $ ad [2], ......
- By http://www.tongqiong.com
- */
- $ Ad [1] = "Tongnan 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;
- }
- /* 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.
- By http://www.tongqiong.com
- 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.
- */
- ?>
|