Home > Article > Backend Development > How to implement non-repeating strings in php
How to implement non-repeating strings in php: First create a PHP sample file; then use the "function rand($len){...}" method to generate non-repeating random strings.
The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.
Recommendation: "PHP Video Tutorial"
How to implement non-repeating strings in php:
php Generate a non-repeating random string
Use the timestamp as the original string, then randomly generate five characters and insert them randomly into any position to generate a new string, ensuring no repetition
function rand($len) { $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $string=time(); for(;$len>=1;$len--) { $position=rand()%strlen($chars); $position2=rand()%strlen($string); $string=substr_replace($string,substr($chars,$position,1),$position2,0); } return $string; }
This method is applicable to all computer models.
The above is the detailed content of How to implement non-repeating strings in php. For more information, please follow other related articles on the PHP Chinese website!