PHP randomly generated string instance explained

Source: Internet
Author: User
This article is for you to introduce in detail the PHP method of giving birth to random strings, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share the PHP produced random strings of the specific code for your reference, the specific content as follows


function generaterandomstring ($length = ten) {   $characters = ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';   $randomString = ";   for ($i = 0; $i < $length; $i + +) {     $randomString. = $characters [rand (0, strlen ($characters)-1)];   }   return $randomString; }echo generaterandomstring (20);/** * Randomly generated string * @param int $length * @return null|string */private static function Getrandc Har ($length = 8) {  $str = null;  $strPol = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz";  $max = strlen ($strPol)-1;   for ($i =0; $i < $length; $i + +) {    $str. = $strPol [rand (0, $max)];//rand ($min, $max) generates a random integer between min and Max two numbers  }   return $str;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.