Php: how to insert random keywords into strings -- example function

Source: Internet
Author: User
Php: how to insert random keywords into strings. example: how to insert several keywords randomly in a function in an article (the number of keywords should be controllable)
Insert random keywords to the random position of the article.
For example, the limit is to insert three keywords. The number of keywords inserted in the article is three.
The insert position is also random.

Examples of functions


Reply to discussion (solution)

If the document does not contain html tags, the problem is simple.
However, if the problem exists, the problem becomes very complicated.

What kind of situation do you plan to deal? Let's talk about it!

It is a TXT text without html tags.

$ S = <TXT randomly inserts several keywords in an article (the number of keywords should be controllable) insert random keywords at random positions in the article. For example, the limit is to insert three keywords. The number of keywords inserted in the article is three. The insert position is also random. 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 must be controllable)
  
Insert random keywords to the random position of the article.
[Random]
For example, the limit is to insert three keywords [insert ]. In the keyword chapter, there are three keywords inserted.
The insert position is also random.

$ S = <TXT randomly inserts several keywords in an article (the number of keywords should be controllable) insert random keywords at random positions in the article. For example, the limit is to insert three keywords. The number of keywords inserted in the article is three. The insert position is also random. 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 must be controllable)
    
Insert random keywords to the random position of the article.
[Random]
For example, the limit is to insert three keywords [insert ]. In the keyword chapter, there are three keywords inserted.
The insert position is also random.

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