|
PHP生成隨機(jī)字符串的函數(shù),可自定義生成的字符串長(zhǎng)度。
<?php
/** **隨機(jī)字符串生成函數(shù) **/ function random_string($length, $max=FALSE) { if (is_int($max) && $max > $length) { $length = mt_rand($length, $max); } $output = ''; for ($i=0; $i<$length; $i++) { $which = mt_rand(0,2); if ($which === 0) { $output .= mt_rand(0,9); } elseif ($which === 1) { $output .= chr(mt_rand(65,90)); } else { $output .= chr(mt_rand(97,122)); } } return $output; } ?> 本文出處參考:http://www./article/445.html |
|
|