ajaxray/short-code 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ajaxray/short-code

最新稳定版本:v1.1.0

Composer 安装命令:

composer require ajaxray/short-code

包简介

ShortCode generator for PHP. Create short, reversible or random, hash like codes.

README 文档

README

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License

ShortCode generator for PHP. Create short, hash like codes. Codes can be random or reversible. Output format is customizable (see the list below).
You can generate random string code of your desired character length, e.g. 4, 6, 8 ... up to 20.
Also, you can generate reversible codes from numbers. It's useful when you'll need to trace the original number from a reference code string.

Can be used for generating small reference codes, tiny URLs or any other purpose.

Installation

Install the latest version with

$ composer require ajaxray/short-code

Supported Output and Conversion Formats

  • ShortCode\Code::FORMAT_ALNUM : (Default) Alphanumaric characters. includes 0-9, a-z and A-Z
  • ShortCode\Code::FORMAT_ALNUM_CAPITAL : Alphanumaric characters. includes 0-9 and A-Z
  • ShortCode\Code::FORMAT_ALNUM_SMALL : Alphanumaric characters. includes 0-9 and a-z
  • ShortCode\Code::FORMAT_CHAR_CAPITAL : Capital letter characters. includes only A-Z
  • ShortCode\Code::FORMAT_CHAR_SMALL : Small letter characters. includes only a-z
  • ShortCode\Code::FORMAT_NUMBER : Numbers. includes only 0-9. Can be used for random number generation

Generating Random Code

<?php
ShortCode\Random::get(); 
// Something like (8 chars by default) : aWg2m5Q3

ShortCode\Random::get(6); 
// 6 character length. e.g. r43Nx2

ShortCode\Random::get(8, ShortCode\Code::FORMAT_ALNUM_SMALL); 
// 8 characters with alnum (small letter only). e.g. f43nbg3e2

Generating Reversible Code from numbers

<?php
ShortCode\Reversible::convert(46345223); 
// Output: 38svB

ShortCode\Reversible::revert('38svB');
// Output: 46345223

// If you specify a format for converting, remember to use the same format for reverting
ShortCode\Reversible::convert(46345223, ShortCode\Code::FORMAT_ALNUM_CAPITAL);
// Output: RLC7B

ShortCode\Reversible::revert('RLC7B', ShortCode\Code::FORMAT_ALNUM_CAPITAL);
// Output: 46345223

Reversible code with having a minimum length

You can create code with a minimum output length. You have to mention the length for both, converting and reverting functions.

<?php
// Creating alphanumeric code with minimum 6 character and reverting
ShortCode\Reversible::convert(9876, \ShortCode\Code::FORMAT_ALNUM, 6); 
// Output: 1002zi
ShortCode\Reversible::revert('1002zi', \ShortCode\Code::FORMAT_ALNUM, 6);
// Output: 9876

// Creating small letter only code with minimum 6 character and reverting
ShortCode\Reversible::convert(9876, \ShortCode\Code::FORMAT_CHAR_SMALL, 6);
// Output: baardm
ShortCode\Reversible::revert('baardm', \ShortCode\Code::FORMAT_CHAR_SMALL, 6);
// Output: 9876

Please note that, using this method, you can only ensure the minimum character length. This length may exceed for larger numbers.

Dependency

This library has dependency on BCMath PHP extension. Please check the installation page in case you don't have it configured.

Also it can be installed on linux based os with something similar to -

// FOr php 5.x
sudo apt-get install php-bcmath
// For php 7
sudo apt-get install php7.0-bcmath

"This is the Book about which there is no doubt, a guidance for those conscious of Allah" - Al-Quran

统计信息

  • 总下载量: 68.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 3
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-23