PHP method to generate one or more groups of random strings

墨辰丷
Release: 2023-03-27 13:44:02
Original
1715 people have browsed it

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 = "";
?>
Copy after login

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 = "";
}
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!