码迷,mamicode.com
首页 > Web开发 > 详细

php随机字符串

时间:2015-03-03 11:33:14      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

<?php

 class RandChar{

  function getRandChar($length){
   $str = null;
   $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
   $max = strlen($strPol)-1;

   for($i=0;$i<$length;$i++){
    $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
   }

   return $str;
  }
 }

 $randCharObj = new RandChar();
 echo $randCharObj->getRandChar(5);
?>

 

php随机字符串

标签:

原文地址:http://www.cnblogs.com/zonglonglong/p/4310414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!