Home >Backend Development >PHP Problem >How to implement non-repeating strings in php

How to implement non-repeating strings in php

藏色散人
藏色散人Original
2020-11-23 09:21:542026browse

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.

How to implement non-repeating strings in php

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!

Statement:
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