PHP产生随机字符串函数
PHP 函数 字符串 随机 产生
2023-06-13 09:13:47 时间
<?php
/**
* 产生随机字符串
*
* 产生一个指定长度的随机字符串,并返回给用户
*
* @access public
* @param int $len 产生字符串的位数
* @return string
*/
function randStr($len=6) {
$chars="ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*"; // characters to build the password from
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
$password="";
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
?>
/**
* 产生随机字符串
*
* 产生一个指定长度的随机字符串,并返回给用户
*
* @access public
* @param int $len 产生字符串的位数
* @return string
*/
function randStr($len=6) {
$chars="ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789#%*"; // characters to build the password from
mt_srand((double)microtime()*1000000*getmypid()); // seed the random number generater (must be done)
$password="";
while(strlen($password)<$len)
$password.=substr($chars,(mt_rand()%strlen($chars)),1);
return $password;
}
?>
相关文章
- php拼接循环拼接字符串数组,PHP数组拼接
- 分享一个支持UTF-8的PHP字符串截取函数
- PHP数组排序函数
- 数据深入PHP:从MySQL获取表数据(php获取mysql表)
- PHP 如何调用 MySQL 函数(php调用mysql函数)
- 如何使用PHP中的字符串函数
- PHP中英文混合排版中处理字符串常用的函数
- PHP中的MYSQL常用函数(php下操作数据库必备)
- php函数之子字符串替换str_replace
- php入门学习知识点七PHP函数的基本应用
- php数组函数序列之array_unique()-去除数组中重复的元素值
- PHP将逗号、空格、回车分隔的字符串转换为数组的函数
- PHP序列号生成函数和字符串替换函数代码
- 解析php获取字符串的编码格式的方法(函数)
- php的数组与字符串的转换函数整理汇总
- PHP获取php,mysql,apche的版本信息示例代码