Home > php教程 > PHP源码 > Randomly output verification code!

Randomly output verification code!

WBOY
Release: 2016-08-04 08:53:39
Original
1544 people have browsed it
跳至 [1] [全屏预览]
//1,先用range和array_merge拼凑出一个数组(包含了26个大小写英文字母和10个数字)
$arr = array_merge(range('A','Z'),range('a','z'),range('0','9'));
//2,打乱该数组(shuffle)
shuffle($arr);
//3,使用array_rand随机抽取若干个该数组的下标
$rand_keys = array_rand($arr,4);
$string= '';
//4,根据获得的下标遍历得到相应的字符串
foreach ($rand_keys as $value) {
	$string.=$arr[$value];
}
//5,输出该字符串
echo $string;
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template