sonypradana/convertcode 问题修复 & 功能扩展

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

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

sonypradana/convertcode

Composer 安装命令:

composer require sonypradana/convertcode

包简介

Simple generator to creat uniq id from number and convert back to number/id

README 文档

README

Simple script to creat uniq id from number, support until up to 11.694.146.092.834.141 digit number. With suport convert back to id (string).

We recommended if you need shorter id from long number ex: timestamp, id with large integer, or name think.

Basic convert is creat id from array of string, then build from array index one by one. You can costumize by edit entry of array.

By default array using [0-9][a-z][A-Z] its mean case sensitive. different between AA and aA

Sample

-------------------------------------------------
|       index   |       code    |       number  |
----------------+---------------+----------------
|       94      |       0w      |       94      |
|       95      |       0x      |       95      |
|       96      |       0y      |       96      |
|       ...     |       ...     |       ...     |
|       3842    |       YY      |       3842    |
|       3843    |       YZ      |       3843    |
|       3844    |       Z0      |       3844    |
|       ...     |       ...     |       ...     |
|       238323  |       ZYV     |       238323  |
|       238324  |       ZYW     |       238324  |
|       238325  |       ZYX     |       238325  |
-------------------------------------------------

CLI Support

run test from 1 to 100

php CLI test 1 100

will output

-------------------------------------------------
|       index   |       code    |       number  |
----------------+---------------+----------------
|       1       |       1       |       1       |
|       2       |       2       |       2       |
|       3       |       3       |       3       |
|       4       |       4       |       4       |
|       5       |       5       |       5       |
... 
|       95      |       0x      |       95      |
|       96      |       0y      |       96      |
|       97      |       0z      |       97      |
|       98      |       0A      |       98      |
|       99      |       0B      |       99      |
|       100     |       0C      |       100     |
-------------------------------------------------

other command

php CLI 
php CLI to-code [number]
php CLI from-code [string_code]

Installation

You can directly import this class from your project.

include 'path_to_ConvertCode_file' . '/ConvertCode.php';

If using Composer

composer require sonypradana/convertcode;

Usage

You can make id using declare class or directly.

Using class:

Craet class

use Convert\Converter\ConvertCode;

$ccode = new ConvertCode();

Creat id (string) from number

$ccode->setNumber( 999999 );  // creat id by 99
echo $ccode->getCode();       // will out put -> 4c81

Creat id (string) from id/code/string

$ccode->setCode( '4c82' );  // creat id by code "4c82"
echo $ccode->getNumber();   // will out put -> 1000000

You can also using operator

// plus (+) operator
$ccode->plusOperator(1);    // plus 1
echo $ccode->getNumber();   // will out put -> 1000001
echo $ccode->getCode();     // will out put -> ac83

// minus (-) operator
$ccode->minusOperator(2);    // minus 2
echo $ccode->getNumber();   // will out put -> 999999
echo $ccode->getCode();     // will out put -> ac81

Directly

You also can call function directly

Convert from id/code/string to number

use ConvertCode\Converter\ConvertCode;

$id_number = ConvertCode::ConvertFromCode( "0B" );
echo $id_number; // will out put 99

Convert from number to id/code/string

use ConvertCode\Converter\ConvertCode;

$id_code = ConvertCode::ConvertFromNumber( 99 );
echo $id_code; // will out put "0B"

If you want to get random id/code/string, you can use

use ConvertCode\Converter\ConvertCode;

$id_code = ConvertCode::RandomCode( 4 ); // how many digit code you want
echo $id_code; // random code 

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-12-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固