Use Hashids in php to convert integers into unique strings.

Source: Internet
Author: User
If you need to hide the ID at the front end, you can consider using this product, the generated id is relatively tall, more like Youtube, Youku, Weibo and other id names, such as: XNjkxMTc0MDQ4 Laravel 5 package: https://github.com/vinkla/hashids

Simple and practical example in PHP:

$hashids = new Hashids\Hashids('this is my salt');$id = $hashids->encode(1, 2, 3);$numbers = $hashids->decode($id);

Of course, the package is comprehensive, including Composer package, Laravel 4 package, Laravel 5 package, CodeIgniter spark, Symfony bundle, Kohana module, Wordpress plugin, CakePHP component, Silex package, and Craft plugin featu. You can find the link on the official website.

It also supports JavaScript, Ruby, Python, Java, Scala, PHP, Perl, Swift, Objective-C, C, C ++ 11, Go, Lua, Elixir, ColdFusion, Groovy, kotlin, Nim, VBA, CoffeeScript and for Node. js &. NET language

Use Laravel 5

It is easy to use and detailed in the documentation.

Run

php artisan vendor:publish

Operation to generate the configuration file. the configuration file path is config \ hashids. php:

'alphabet'=> 'your-alphabet-string'

The configuration item is what character you intend to display in the encrypted string. I used A-Z, a-z, 0-9, and later found that it seems to be related to the character sequence, the generated random string is not evenly case-sensitive and numbers. the shuffle () function of PHP is used to disrupt the order and generate a new set of alphabet. then it looks very tall.

Example:

// You can alias this in config/app.php.use Vinkla\Hashids\Facades\Hashids;Hashids::encode(4815162342);// We're done here - how easy was that, it just works!Hashids::decode('doyouthinkthatsairyourebreathingnow');// This example is simple and there are far more methods available.

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.