How PHP inserts a random keyword into a string to find an instance function

Source: Internet
Author: User
Insert several keywords randomly in an article (the number of keywords can be controlled)
Random numbers of random keywords are inserted at random positions in the article.
For example, the limit is to insert 3 keywords. Then the number of keywords inserted in the article is 3.
The inserted position is also a random position.

Seeking the example function to seek the master enlighten


Reply to discussion (solution)

If the article does not contain HTML tags, then the problem is relatively simple
But if it does, the problem is very complicated.

Are you going to take care of that? Think again!

is txt text, no HTML tags

$s =<<< txt inserts a random number of random keywords at random locations in an article by randomly inserting several keywords (the number of keywords you want to control) in an article. For example, the limit is to insert 3 keywords. Then the number of keywords inserted in the article is 3. The inserted position is also a random position. TXT, $w = ' keyword, random, insert ', echo foo ($s, $w), function foo ($txt, $word, $charset = ' gbk ') {foreach (Explode (', ', $word) as $v) $tmp  [] = Iconv ($charset, ' ucs-2 ', "" {$v} ");  $txt = Iconv ($charset, ' ucs-2 ', $txt); for ($i =0; $i
 
  Insert several keywords randomly in an article (the number of keywords can be controlled)
  
Random numbers of random keywords are inserted at random positions in the article.
Random
For example, the limit is to insert 3 words "Insert". Then in the text "keyword" You zhang Li Insert the number of keywords is 3.
The inserted position is also a random position.

 $s =<<< txt randomly inserts several keywords in an article (the number of keywords to be controllable) inserts random numbers of random keywords at random positions in the article. For example, the limit is to insert 3 keywords. Then the number of keywords inserted in the article is 3. The inserted position is also a random position. TXT, $w = ' keyword, random, insert ', echo foo ($s, $w), function foo ($txt, $word, $charset = ' gbk ') {foreach (Explode (', ', $word) as $v) $tmp  [] = Iconv ($charset, ' ucs-2 ', "" {$v} ");  $txt = Iconv ($charset, ' ucs-2 ', $txt); for ($i =0; $i 
    
      randomly inserts a number of keywords (the number of keywords can be controlled) 
     
inserts random numbers of random keywords at random locations in the article.
Random
For example, the limit is to insert 3 keyword "Insert". Then in the text "keyword" You zhang Li Insert the number of keywords is 3. The
inserted position is also a random position.

If there is HTML code, what good method
  • 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.