Replacing multiple URLs in an article with a random number requires that the random numbers following each URL be different. There are many articles in the database. There are many URLs in this article. I want to add random numbers to the URLs, but the random numbers behind each URL are different. I wrote a replacement option, but the result is that after the replacement, the random numbers after each URL are the same for ($ I = 1; $ I & lt; = 60; $ I ++) {$ du: replace multiple URLs in the document with a random number. the random numbers after each URL must be different.
There are many articles in the database. There are many URLs in the article
I want to add a random number after the URL, but the random number after each URL is different.
I wrote a replacement option, but the result is that the random numbers after each URL are the same after the replacement.
For ($ I = 1; $ I <= 60; $ I ++ ){
$ Duoyu = revert (1,111 );
$ Res-> fn_ SQL ("update content set body = replace (body, 'com', 'com $ duoyu') where aid = '$ I '");
}
Please help
------ Solution --------------------
The above code does not guarantee that the random numbers generated in a loop are unique. if the requirements are strict, you need to modify the code:
PHP code
Function addRandNumber ($ matches) {global $ ar; $ n = rand (1,111); while (in_array ($ n, $ ar) $ n = rand (1,111 ); $ ar [] = $ n; return $ matches [1]. $ n ;}$ body = "url_com
Url_com
Url_com "; $ ar = array (); $ body = preg_replace_callback (" | (com) +? | ", 'Addrandnumber', $ body );
------ Solution --------------------
Jquery implementation. Very simple.
$ ("A"). each (function (index, obj)
{
$ (Obj). attr ("href", $ (obj). attr ("href") + "? Rand = "+ Math, random );
})
------ Solution --------------------
Discussion
I can see that csdn experts are always a few