-1

I have a function who generates a Hex number:

function generateUid(){
    $uuid = Uuid::uuid4();
    $uuid = $uuid->getHex();
    $uuid =  substr($uuid,8);

    return   $uuid;
}

The hex has the length of 25 but I want to cut it to only 8 digits.

executable
  • 3,365
  • 6
  • 24
  • 52
peace_love
  • 6,229
  • 11
  • 69
  • 157

1 Answers1

1

The substr first parameter is where to start, and second is the length (number of characters to return). So:

substr($uuid, 0, 8);

Should start at the first position and return 8 characters.

Your previous code:

substr($uuid,8);

started at the 9th character and returned the rest of the string.

user3783243
  • 5,368
  • 5
  • 22
  • 41