Home > php教程 > php手册 > PHP生成自定义长度随机字符串的函数

PHP生成自定义长度随机字符串的函数

WBOY
Release: 2016-06-13 09:35:57
Original
1845 people have browsed it

   这篇文章主要介绍了PHP生成自定义长度随机字符串的函数分享,需要的朋友可以参考下

  php随机生成字符串可以自己定义自己所需要的长度,在实际应用开发中,经常遇到。

  代码如下:

  //随机生成字符串

  function random($length) {

  srand(date("s"));

  $possible_charactors = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  $string = "";

  while(strlen($string)

  $string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);

  }

  return($string);

  }

        :更多精彩文章请关注帮客之家编程教程栏目。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template