开发者

How can I randomize an entire string of 62 characters?

开发者 https://www.devze.com 2022-12-21 07:48 出处:网络
I have 62 base64 characters that I want to randomize. How can I do this using PHP? The string would be all letters, upper and lower case as well as开发者_如何学Go numbers from 0-9.

I have 62 base64 characters that I want to randomize. How can I do this using PHP? The string would be all letters, upper and lower case as well as开发者_如何学Go numbers from 0-9.

The thing that is most important to me is that the entire string be evaluated before a return value is given. In other words, if I request a string of 8 characters in length and my string starts out like:

1234567890ABCDE..... I don't want to get the first 8 numbers randomized. It should randomize the entire string first, then return 8 characters from that.


Try this:

$string = '1234567890ABCDE...';

$string = substr(str_shuffle($string), 0, 8);

str_shuffle randomizes the string, then substr takes the first 8 characters from it.


Take a look at str_shuffle.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号