PHP code example of efarsoft / ulid

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

    

efarsoft / ulid example snippets



use Efarsoft\Ulid;

$ulid = Ulid::generate();
echo (string) $ulid; 
// 01B8KYR6G8BC61CE8R6K2T16HY

// 输出小写字符串
$ulid = Ulid::generate(true);
echo (string) $ulid; 
// 01b8kyr6g8bc61ce8r6k2t16hy

// 转换为Unix 时间戳
$ulid = Ulid::generate();
echo $ulid->toTimestamp(); 
// 1561622862

// 使用毫秒时间戳生成Ulid
$ulid = Ulid::fromTimestamp(1593048767015);
//$ulid = Ulid::fromTimestamp(1593048767015, true);
echo (string) $ulid; 
// 01EBMHP6H7TT1Q4B7CA018K5MQ