Questions about randomly reading and replacing data from the database

Source: Internet
Author: User
There is a text about randomly reading data from the database and replacing them one by one. $ str I need to replace all the keywords $ key in this text with PHPcode // rand () randomly read data //..... //..... $ str = str_ireplace ({key}, & quot ;. $ Rs [& quot; title & quot; questions about randomly reading data from the database and replacing them one by one
There is a text $ str

I need to replace the keyword $ key in this text.

Replace all
PHP code
  // Rand () random read data //..... //..... $ str = str_ireplace ({key },". $ Rs ["title"] "", $ str); echo $ str;


How can we replace them one by one without repeating them?




------ Solution --------------------
Since it is "random", repetition cannot be avoided.
------ Solution --------------------
Random, one by one? It sounds a little contradictory.
------ Solution --------------------
The description is vague. You just need to random the key.
------ Solution --------------------
If $ key is an array, $ k = array_rand ($ key, 1); replace with $ k
------ Solution --------------------
For ($ I = 0; $ I <5; $ I ++ ){
$ String = str_ireplace ("Hello", "Hello $ I", $ string );
}

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.