PHP Generate short domain name function _php Tutorial

Source: Internet
Author: User

PHP generates a short domain name function


Short URLs have been popular for some time, the previous Sina Weibo application when there is contact, but did not make it clear, recently again contact this east, carefully studied the next, found that the short URL is actually quite easy. The following will use PHP to generate a short URL implementation method to do a record.

PHP generates a short domain name function

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

Public Function Createrandcode ($string) {

$code = ";

$hex _code = ' 1qaz2wsx3edc4rfv5t-gb6yhn7ujm8ik9ol0p_ ';

$now = Microtime (True) * 10000;

$strlen = strlen ($hex _code);

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

This defines a random length for the encoding, depending 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 the article to share the entire content of the code, I hope you can like.

http://www.bkjia.com/PHPjc/973140.html www.bkjia.com true http://www.bkjia.com/PHPjc/973140.html techarticle PHP generated short domain name function short URL popular has been a period of time, used to do Sina Weibo application when there is contact, but did not make it clear, recently again contact this dongdong, carefully ...

  • 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.