PHP Classes

File: sample/ulid-sample.php

Recommend this page to a friend!
  Classes of Leonardo Di Sarli   PHP Generate ULID   sample/ulid-sample.php   Download  
File: sample/ulid-sample.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Generate ULID
Generate, validate, and recover ULID values
Author: By
Last change:
Date: 10 months ago
Size: 1,035 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
Ulid\Ulid;


print_r('Generate Ulids');
echo
PHP_EOL;
$ulid = new Ulid();

$ulidFromTime = $ulid->generate(1585083964945);
echo
'ulid from time (1585083964945) = ' . $ulidFromTime . PHP_EOL;

$ulidFromNow = $ulid->generate();
echo
'ulid from now = ' . $ulidFromNow . PHP_EOL;

$invalid = $ulid->isValidFormat('1585083964945');
echo
'invalid format = ' . $invalid . PHP_EOL;

$valid = $ulid->isValidFormat('01E475VQGHA88VWQ4H22GQ3X3T');
echo
'valid format = ' . $valid . PHP_EOL;

$timeFromUlid = $ulid->getTimeFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo
'get time from ulid (01E48SD97BMWHAW82D229T0C7K) = ' . $timeFromUlid . PHP_EOL;

$dateFromUlid = $ulid->getDateFromUlid('01E48SD97BMWHAW82D229T0C7K');
echo
'get date from ulid (01E48SD97BMWHAW82D229T0C7K) = ' . $dateFromUlid . PHP_EOL;

$randomnessFromUlid = $ulid->getRandomnessFromString('01E475VQGHNW990PVHXFDT4C6R');
echo
'get randomness from ulid (01E475VQGHNW990PVHXFDT4C6R) = ' . $randomnessFromUlid . PHP_EOL;