Home > Article > Backend Development > PHP method to generate one or more groups of random strings
This article mainly introduces the method of PHP to simply generate one or more groups of random strings, involving PHP's random string-related operating skills based on the rand method. Friends in need can refer to it
The details are as follows :
Generate one group:
<?php $str = "0123456789abcdefghijklmnopqrstuvwxyz~@#()_";//输出字符集 $n = 10;//输出串长度 $len = strlen($str)-1; for($i=0 ; $i<$n; $i++){ $s .= $str[rand(0,$len)]; } echo $s . "<br/>"; $s = ""; ?>
Generate multiple Group:
<?php $str = "0123456789abcdefghijklmnopqrstuvwxyz~@#()_";//输出字符集 $n = 10;//输出串长度 $len = strlen($str)-1; for($j=0 ; $j<200 ; $j++){ for($i=0 ; $i<$n; $i++){ $s .= $str[rand(0,$len)]; } echo $s . "<br/>"; $s = ""; } ?>
Related recommendations:
php generates custom lengthrandom stringdetailed steps
php achieves generation Methods for random string
##thinkphpRandom string
The above is the detailed content of PHP method to generate one or more groups of random strings. For more information, please follow other related articles on the PHP Chinese website!