16 bytes binary form representing canonical uuid in php

how can i get the 16 bit uuid binary form from its string / canonical representation:

eg: 1968ec4a-2a73-11df-9aca-00012e27a270

amuses / Marcin

+3
source share
2 answers
 $bin = pack("h*", str_replace('-', '', $guid));

pack

+10
source

If you are exactly reading the chapter on the format and string representation of UUIDs as defined by DCE, you cannot naively treat a UUID string as a hexadecimal string, see String Representing UUIDs (referred to by the Microsoft Developer Network ). That is, because the first three fields are presented at the big end (first of all, a significant figure).

, (, , ) , PHP 32bit, :

$bin = call_user_func_array('pack',
                            array_merge(array('VvvCCC6'),
                                        array_map('hexdec',
                                                  array(substr($uuid, 0, 8),
                                                        substr($uuid, 9, 4), substr($uuid, 14, 4),
                                                        substr($uuid, 19, 2), substr($uuid, 21, 2))),
                                        array_map('hexdec',
                                                  str_split(substr($uuid, 24, 12), 2))));

, , pack.

, , , , . pack.

0

Source: https://habr.com/ru/post/1737834/


All Articles