PHP code example of semperton / multibase

1. Go to this page and download the library: Download semperton/multibase 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/ */

    

semperton / multibase example snippets


use Semperton\Multibase\Base62;
use Semperton\Multibase\Base85;

// basic usage
$base62 = new Base62();
$base62->encode('Hello World'); // 73XpUgyMwkGr29M
$base62->decode('73XpUgyMwkGr29M'); // Hello World

// shorten md5 hash
$hash = md5('Hello World'); // b10a8db164e0754105b7a99be72e3fe5

$short = $base62->encode(hex2bin($hash)); // 5O4SoozqXEOwlYtvkC5zkr
$short = $base62->encode(md5('Hello World', true)); // same as above

$decoded = $base62->decode($short);
$hash === bin2hex($decoded); // true

// password generation
$bytes = openssl_random_pseudo_bytes(16);
$password = (new Base85())->encode($bytes); // e.g. Ncg>RWSYO+2t@~G8PO0J


use Semperton\Multibase\Transcoder\BaseTranscoder;

$emojiTranscoder = new BaseTranscoder(
	'πŸ§³πŸŒ‚β˜‚οΈπŸ§΅πŸͺ‘πŸͺ’πŸ§ΆπŸ‘“πŸ•ΆπŸ₯½πŸ₯ΌπŸ¦ΊπŸ‘”πŸ‘•πŸ‘–πŸ§£πŸ§€πŸ§₯πŸ§¦πŸ‘—πŸ‘˜πŸ₯»πŸ©΄πŸ©±πŸ©²' .
	'πŸ©³πŸ‘™πŸ‘šπŸ‘›πŸ‘œπŸ‘πŸŽ’πŸ‘žπŸ‘ŸπŸ₯ΎπŸ₯ΏπŸ‘ πŸ‘‘πŸ©°πŸ‘’πŸ‘‘πŸ‘’πŸŽ©πŸŽ“πŸ§’β›‘πŸͺ–πŸ’„πŸ’πŸ’Ό'
);

$encoded = $emojiTranscoder->encode('Hello World'); // β˜‚πŸͺ’πŸ‘ŸπŸ©΄πŸ©°πŸ₯»πŸ‘šπŸ‘™πŸ§’🩲πŸ§₯πŸ₯½πŸŽ©πŸ‘™πŸ‘πŸŽ’
$emojiTranscoder->decode($encoded); // Hello World