zoukankan      html  css  js  c++  java
  • PHP生成随机字符串

    随机字符串生成:

    来自:http://blog.sina.com.cn/s/blog_6d4bfb040100pupr.html

    <?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);
    ?>

    80个随机字符串生成

    <?php
    class RandChar{
    
      function getRandChar($length){
       $str = null;
       $strPol = "0123456789abcdefghijklmnopqrstuvwxyz";
       $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();
    $word=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word1=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word2=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word3=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word4=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word5=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word6=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    $word7=array($randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5),$randCharObj->getRandChar(5));
    print_r($word);echo "<br />";
    print_r($word1);echo "<br />";
    print_r($word2);echo "<br />";
    print_r($word3);echo "<br />";
    print_r($word4);echo "<br />";
    print_r($word5);echo "<br />";
    print_r($word6);echo "<br />";
    print_r($word7);echo "<br />";
    
    ?>
  • 相关阅读:
    Scala Partial Function从官方文档解析
    Scala Option 从官方DOC解析
    Scala Nothing 从官方DOC翻译
    从HTTP request的body中拿到JSON并反序列化为一个对象
    将一个大文件分割成若干个小文件,每个文件最多10万行
    java 可变长度参数列表
    java Class类的用法示例
    java String int转换的不同方法
    转载:大公司与小公司的比较
    java 判断5张牌的组成
  • 原文地址:https://www.cnblogs.com/4php/p/3503244.html
Copyright © 2011-2022 走看看