zoukankan      html  css  js  c++  java
  • 随机生成字符串,数字,手机号,邮箱

    /**
    * echo nRand('mail');die;
    * @param
    array $type
    * @param
    int $len
    * @return
    int|string
    */
    function nRand($type=[],$len= 20
    )
    {
    $t = gettype($type
    );
    if($t === 'string'
    ){
    $rand=""
    ;
    if($type == 'phone'
    )
    {
    $rand=0
    ;
    for ($i = 1; $i < 9; ++$i
    ) {
    $rand .=mt_rand(0, 9
    );
    }
    return (int) '13'.$rand
    ;
    }elseif($type === 'mail'
    ){
    $rand=0
    ;
    for ($i = 1; $i < 9; ++$i
    ) {
    $rand .=mt_rand(0, 9
    );
    }
    return '13'.$rand.'@'.$rand.'com'
    ;
    }else
    {
    for ($i = 0; $i < $len; $i
    ++)
    {
    $rand .= chr(mt_rand(33, 126
    ));
    }
    return $rand
    ;
    }

    }elseif ($t === "integer"){
    $rand=0
    ;
    $str = '0123456789'
    ;
    $max=strlen($str)-1
    ;
    for ($i = 1; $i < $len; ++$i
    ) {
    $rand .=$str[mt_rand(0, $max
    )];
    }
    return $rand
    ;
    }else
    {
    $rand = ''
    ;
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwsyz0123456789'
    ;
    $max=strlen($str)-1
    ;
    for ($i = 1; $i <= $len; ++$i
    ) {
    $rand .=$str[mt_rand(0, $max
    )];
    }
    return $rand
    ;
    }

    }
  • 相关阅读:
    自定义指令directive
    angular中的表单验证
    ng-init,ng-controller,ng-model
    Redis执行lua脚本,key不存在的返回值
    消息队列对比
    数据库设计范式
    网络IO模型
    .NET 线程、线程池
    异步和多线程
    Memcache知识点
  • 原文地址:https://www.cnblogs.com/q1104460935/p/7045124.html
Copyright © 2011-2022 走看看