How to implement non-repeating strings in php

藏色散人
Release: 2023-03-07 18:46:01
Original
1989 people have browsed it

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;
    }
Copy after login
  • 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!

Related labels:
php
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template