How does php generate a non-repeated string?

Source: Internet
Author: User
How can I generate a non-duplicate string using php? As shown in the end after youtube, the string 6Af6b_wyiwI (a character acceptable to the website) is displayed. What are the differences between the characters in size and wyiwi? You can also set the length of each output string, for example, 4 ~ 7. the machine will become ga79eaa09gswawe9f equivalent (... how can I use php to generate a non-duplicate string?
As the string after the end of youtube will appear: 6Af6b_wyiwI (acceptable Web site characters)
What's the difference between the size and the number of shards?
You can also set the length of each output string.
Example 4 ~ 7
This will change to ga79e aa09gsw awe9f category (this will happen every time)

Reply content:

How can I generate a non-duplicate string using php?
As the string after the end of youtube will appear: 6Af6b_wyiwI (acceptable Web site characters)
What's the difference between the size and the number of shards?
You can also set the length of each output string.
Example 4 ~ 7
This will change to ga79e aa09gsw awe9f category (this will happen every time)

We recommend that you use the timestamp, which can be encrypted by MD5 or sha1, but the length is fixed in case. you can intercept the data or customize the encryption rules. you can set the desired length. There is no possibility of repeated operations (impossible events)
If you define your own string and obtain it at random, there is a possibility of repetition (small probability event ).
If you write a url
You can also refer to segmentfault url writing

Https://segmentfault.com/q/10...

Generate a sequence of sequential growth, and convert it to a string using ascii code

Conversion between PHP 10 and 62:

echo gmp_strval(gmp_init('9876543210', 10), 62)."\n"; //AmOy42echo gmp_strval(gmp_init('AmOy42', 62), 10)."\n";     //9876543210

The above AmOy42 should be the "string" you want. In fact, it is a 62-digit number.
In the 62-digit system (10 + 26 + 26), 10 digits, 26 lower-case letters, and 26 upper-case letters are used to represent values, greatly reducing the number of digits.
9876543210 is the auto-increment ID in the database, which is unique.

In a simple way, hash algorithms such as sha256 obtain binary data (instead of a hexadecimal string) and then use base64 encoding.

Refer to the short link generation method.

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.