php生成字符串随机码实现方法
来源:程序员人生 发布时间:2014-03-22 14:26:06 阅读次数:3582次
- */
- $validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
- $index = mt_rand(0, 10);
- echo $index;
-
- $validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
- $validcharnumber = strlen($validcharacters);
- $index = mt_rand(0, $validcharnumber-1);
- $randomcharacter = $validcharacters[$index];
- echo $randomcharacter;
-
- $length = 5;
- $result = "";
- for ($i = 0; $i < $length; $i++) {
- $index = mt_rand(0, $validcharnumber-1);
- $result .= $validcharacters[$index];
- }
-
- function getrandomstring($length = 6) {
- $validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
- $validcharnumber = strlen($validcharacters);
- $result = "";
- for ($i = 0; $i < $length; $i++) {
- $index = mt_rand(0, $validcharnumber - 1);
- $result .= $validcharacters[$index];
- }
- return $result;
- }
- echo getrandomstring();
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠