Home  >  Article  >  Backend Development  >  PHP随机生成随机个数的字母组合示例_PHP

PHP随机生成随机个数的字母组合示例_PHP

WBOY
WBOYOriginal
2016-06-01 11:57:35858browse

在很多系统环境下大家都会用到字母组合各种编码,下面推荐大家非常实用的PHP代码。

$num由几个字母组合。

$s字母包含大小写,可以自己调配大写还小写。
复制代码 代码如下:
function makecode($num=4) {
$re = ”;
$s = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
while(strlen($re)$re .= $s[rand(0, strlen($s)-1)]; //从$s中随机产生一个字符
}
return $re;
}

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