20c01-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 37 行

PHP
37
字号
<?php// A function that accepts a parameter to specify a length, and then returns// a random password with characters and lettersfunction random_password($length = 8) {	// Declare a blank string to start from	$pass = '';		// Now loop for as many times as the length	for ($i = 0; $i < $length; $i++) {		// For this character, first give an equal chance of upper,lower,num		switch (rand(0,2)) {			case 0: 				// Generate a Number from 0 to 9				$pass .= rand(0,9);				break;			case 1:				// Generate a letter from A to Z via ascii values 65 to 90				$pass .= chr(rand(65,90));				break;			default:				// Instead use a letter from a to z, via ascii 97 to 122				$pass .= chr(rand(97,122));		}	}		// Return that password!	return $pass;}// Test this, echo out a batch of 10 passwords, from 1 to 10 characters longecho "<ol>\n";foreach (range(1,10) as $l) {	$tmp = random_password($l);	echo "<li>{$tmp}</li>\n";}echo "</ol>\n";?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?