Home  >  Article  >  Backend Development  >  PHP method to generate one or more groups of random strings

PHP method to generate one or more groups of random strings

墨辰丷
墨辰丷Original
2018-05-22 15:56:271729browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn