PHP code example of kiwfy / ulid-php

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

    

kiwfy / ulid-php example snippets


use Ulid\Ulid;
$ulid = new Ulid();
$ulidFromNow = $ulid->generate();
echo $ulidFromNow;

use Ulid\Ulid;
$ulid = new Ulid();
$ulidFromTime = $ulid->generate(1585083964945);
echo $ulidFromTime;

use Ulid\Ulid;
$ulid = new Ulid();
$invalid = $ulid->isValidFormat('1585083964945');
var_dump($invalid)

use Ulid\Ulid;
$ulid = new Ulid();
$timeFromUlid = $ulid->getTimeFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo $timeFromUlid;

use Ulid\Ulid;
$ulid = new Ulid();
$dateFromUlid = $ulid->getDateFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo $dateFromUlid;

use Ulid\Ulid;
$ulid = new Ulid();
$randomnessFromUlid = $ulid->getRandomnessFromString('01E475VQGHNW990PVHXFDT4C6R');
echo $randomnessFromUlid;
sh
composer 
sh
php sample/ulid-sample.php