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 );
}