Php short domain name function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php generates short domain name functions. Php has generated a short domain name function. The short website has been popular for some time. I used to have contact with Sina Weibo apps before, but I have not figured it out. recently I have come into contact with this stuff again, carefully generate short domain name functions in php

The short website has been popular for some time. I used to have contact with Sina Weibo apps before, but I have not figured it out. recently I have come into contact with this stuff and studied it carefully, it is also easy to find short URLs. The following describes how to generate a short URL using php.

Php short domain name generation function

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Public function createRandCode ($ string ){

$ Code = '';

$ Hex_code = '1qaz2wsx3edc4rfv5t-gb6yhn7ujm8ik9ol0p _';

$ Now = microtime (true) * 10000;

$ Strlen = strlen ($ hex_code );

$ Hash_code = hash ('sha256 ', $ string );

// A random length is defined for the encoding. the length depends on the step.

$ Step = rand (8, 16 );

$ Count = ceil (strlen ($ hash_code)/$ step );

For ($ I = 0; $ I <$ count; $ I ++ ){

$ Start = $ I * $ step;

$ Hex_num = substr ($ hash_code, $ start, $ step );

$ Num = 0x3fffffff & (1 * '0x '. $ hex_num );

$ N = $ num % $ strlen;

$ Code. = $ hex_code [$ n];

}

Return $ code;

}

The above is all the content of the code shared in this article. I hope you will like it.

The short Web site has been popular for some time. I used to have contact with Sina Weibo apps before, but I didn't know it clearly. recently I 've come to contact this stuff again. please be careful...

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.