English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

php analysis of generating random strings using str_shuffle() function

This article describes the method of generating a random string using the str_shuffle() function in PHP. Shared for everyone's reference, as follows:

str_shuffle(): Randomly shuffle the order of the string.

By combining the str_shuffle() function with the substr() function, you can generate a string that is different each time.

Here are two examples of the str_shuffle() function:

Example 1:Randomly generate strings of length10Bit numeric string.

$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
str_shuffle($str);
$name=substr(str_shuffle($str),26,10);
echo $name;

Run Result: bdgNIC04wF

Example 2:Generated a string starting with NT.10Bit String.

$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
$str='NT'.substr(str_shuffle($str),5,8);
echo $str;

Run Result: NTZYwKiDaF

PS: Here is another online tool with similar functions for your reference:

Online Random Number/String Generation Tool:
http://tools.jb51.net/aideddesign/suijishu

High Strength Password Generator:
http://tools.jb51.net/password/CreateStrongPassword

Readers who are interested in more about PHP-related content can check out the following special topics on this site: 'Summary of PHP string (string) usage', 'PHP Data Structures and Algorithms Tutorial', 'Summary of PHP program design algorithms', 'Summary of PHP sorting algorithms', 'Summary of common PHP traversal algorithms and techniques', 'Summary of PHP mathematical operation techniques', 'Comprehensive PHP array (Array) operation techniques', and 'Summary of common database operation techniques in PHP'.

I hope this article will be helpful to everyone in PHP program design.

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You may also like