PHP URL Shortening Algorithm

后端 未结 7 853
说谎
说谎 2020-12-28 09:22

Could anyone recommend a preferred algorithm to use for URL shortening? I\'m coding using PHP. Initially I thought about writing something that would start at a character su

相关标签:
7条回答
  • 2020-12-28 09:43

    You can use base_convert function to do a base convertion from 10 to 36 with the database IDs.

    <?php
       $id = 315;
       echo base_convert($id, 10, 36), "\n";
    ?>
    

    Or you can reuse some of the ideas presented in the comments on the page bellow:

    http://php.net/manual/en/function.base-convert.php

    0 讨论(0)
提交回复
热议问题