PHP成随机字符串
PHP 字符串 随机
2023-09-27 14:26:43 时间
/**
* 随机字符串
* @param int $len
* @return string
*/
function randomStr($len = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz";
$shuffle = str_shuffle($chars);
$result = '';
for ($i=0;$i<$len;$i++)
{
$index = mt_rand(0,strlen($chars));
$result .= substr($shuffle,$index,1);
}
return $result;
}
/**
* 生成随机数
* @param int $len
* @return string
*/
function randomNum($len = 6)
{
$arr = range(0,9);
$result = '';
for ($i=0;$i<$len;$i++)
{
$result .= $arr[mt_rand(0,count($arr)-1)];
}
return $result;
}
相关文章
- PHP Libxml函数
- 小胖学PHP总结4-----PHP的字符串操作
- PHP RSA 生成公钥私钥 PSA2 加密解密
- PHP strpos() 函数查找字符串在另一字符串中第一次出现的位置
- 在cmd窗口中运行php命令
- php Internal Server Error
- PHP 之 FastCGI 与 mod_php 详解
- php-fpm优化
- 《写给PHP开发者的Node.js学习指南》一2.2 预定义的PHP变量
- PHP字符串比较,看起来值完全一样,但是就是不相等的解决方案(‌)
- PHP中一些常用知识点
- 深入理解php内核 编写扩展 I:介绍PHP和Zend
- PHP 字符串转 bigint 型md5
- php中带mb的字符串处理函数
- PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数
- php转换字符编码为utf-8
- PHP 关键词
- php截取包含中英文的字符串固定长度
- PHP-Java-Bridge使用笔记