English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
В этой статье описывается метод генерации случайных строк с использованием функции str_shuffle() в php. Предлагается к рассмотрению, как указано ниже:
str_shuffle(): случайное перемешивание顺序 строки.
С помощью комбинации функций str_shuffle() и substr() можно генерировать уникальные строки каждый раз.
Вот два примера функции str_shuffle():
Пример один:Создание случайной строки из 10 цифр.
$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"; str_shuffle($str); $name=substr(str_shuffle($str),26,10); echo $name;
Running result: bdgNIC04wF
Example two:Generated a 10-character string starting with NT.
$str="QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm"; $str='NT'.substr(str_shuffle($str),5,8); echo $str;
Running result: NTZYwKiDaF
PS: Here is another online tool with similar functions for your reference:
Online random number/character generation tool:
http://tools.jb51.net/aideddesign/suijishu
High-strength password generator:
http://tools.jb51.net/password/CreateStrongPassword
Readers who are interested in more PHP-related content can check the special topic of 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', 'Complete manual of PHP array (Array) operation techniques', and 'Summary of common database operation techniques in php'.
I hope this article will be helpful to everyone's 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 liabilities. If you find any content suspected of copyright infringement, please send an email to notice#oldtoolbag.com (replace # with @ when sending an email) for reporting and provide relevant evidence. Once verified, this site will immediately delete the suspected infringing content.