Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carry0987/cony
Cony is a PHP library for convert integer into alphabet, and reversely too
https://github.com/carry0987/cony
bcmath composer converter hash php
Last synced: 24 days ago
JSON representation
Cony is a PHP library for convert integer into alphabet, and reversely too
- Host: GitHub
- URL: https://github.com/carry0987/cony
- Owner: carry0987
- License: mit
- Created: 2023-10-11T06:37:08.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-21T13:58:03.000Z (6 months ago)
- Last Synced: 2024-11-15T21:36:45.570Z (about 2 months ago)
- Topics: bcmath, composer, converter, hash, php
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cony
[![Packgist](https://img.shields.io/packagist/v/carry0987/cony.svg?style=flat-square)](https://packagist.org/packages/carry0987/cony)
Cony is a PHP library for convert integer into alphabet, and reversely too## Installation
```bash
composer require carry0987/cony
```
> **Note** You can install [`bcmath`](https://secure.php.net/manual/en/book.bc.php) extension in order to get better performance## Usage
```php
require dirname(__DIR__).'/vendor/autoload.php';use carry0987\Cony\Cony;
echo Cony::toNumeric('test'); // 4544743
echo '
';
echo Cony::toAlphanumeric(4544743); // test
```If you want the alphaID to be at least 3 letter long, use the `$padUp` argument.
> In most cases this is better than totally random ID generators because this can easily avoid duplicate ID's.
>
> For example if you correlate the alpha ID to an auto incrementing ID in your database, you're done.
```php
Cony::toAlphanumeric(4540899, 3); // test
Cony::toNumeric('test', 3); // 4540899
```Although this function's purpose is to just make the ID short - and not so much secure, with third argument `secureKey` you can optionally supply a password to make it harder to calculate the corresponding numeric ID.
```php
Cony::toAlphanumeric(11282993, 3, 'heuh2ui12'); // test
Cony::toNumeric('test', 3, 'heuh2ui12'); // 11282993
```And, for final, you can easy transform alphanumeric result:
```php
Cony::toAlphanumeric(21663528, 0, null, Cony::TRANSFORM_UPPERCASE); // B2TFK
Cony::toAlphanumeric(21663528, 0, null, Cony::TRANSFORM_LOWERCASE); // b2tfk
```