PHP code example of ajaxray / short-code

1. Go to this page and download the library: Download ajaxray/short-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ajaxray / short-code example snippets



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


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


// 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

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