PHP code example of doughmii / dev-utils

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

    

doughmii / dev-utils example snippets


use DoughMii\DevUtils\Id\Base62Encoder;

$encoder = new Base62Encoder();

// Encode and decode a single integer
$encoded = $encoder->encode(123456);
$decoded = $encoder->decode($encoded);

// Encode and decode with salt
$encodedSalted = $encoder->encode(123456, 'my-salt');
$decodedSalted = $encoder->decode($encodedSalted, 'my-salt');

// Encode and decode multiple integers
$data = [1, 2, 3];
$encodedMultiple = $encoder->encodeMultiple($data, 'salt123');
$decodedMultiple = $encoder->decodeMultiple($encodedMultiple, count($data), 'salt123');

use DoughMii\DevUtils\Time\TimeHumanizer;

$now = new DateTimeImmutable();
$past = $now->modify('-3 days');

echo TimeHumanizer::diffForHumans($past); // e.g. "3 days ago"
echo TimeHumanizer::fromNow($past);       // same as above

// With custom locale (zh)
echo TimeHumanizer::diffForHumans($past, null, 'zh'); // "3 天前"