generate uuid in php

To generate a UUID using PHP, you can use the ramsey/uuid package. This package provides a simple API for generating and working with UUIDs in PHP. Here's an example code snippet that generates a random version 4 UUID:

main.php
use Ramsey\Uuid\Uuid;

$uuid4 = Uuid::uuid4();
echo $uuid4->toString(); // outputs something like '5b5d3520-9795-4e3a-a45e-1a6b5b8b4939'
137 chars
5 lines

This code first imports the Uuid class from the ramsey/uuid package. It then generates a version 4 UUID using the uuid4() method. Finally, it outputs the UUID as a string using the toString() method.

Note that you'll need to install the ramsey/uuid package using Composer before you can use it. You can do this by adding ramsey/uuid to your project's composer.json file and then running composer install:

{
    "require": {
        "ramsey/uuid": "^4.0"
    }
}
57 chars
6 lines

gistlibby LogSnag