Format "raw" string to Java UUID in PHP Format "raw" string to Java UUID in PHP curl curl

Format "raw" string to Java UUID in PHP


Your question doesn't make much sense but assuming you want to read the UUID in the correct format in Java you can do something like this:

import java.util.UUID;class A{    public static void main(String[] args){        String input = "f9e113324bd449809b98b0925eac3141";                                 String uuid_parse = input.replaceAll(                                                                    "(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})",                                                    "$1-$2-$3-$4-$5");                                                              UUID uuid = UUID.fromString(uuid_parse);        System.out.println(uuid);    }}

Borrowed from maerics, see here: https://stackoverflow.com/a/18987428/4195825

Or in PHP you can do something like:

<?php     $UUID = "f9e113324bd449809b98b0925eac3141";    $UUID = substr($UUID, 0, 8) . '-' . substr($UUID, 8, 4) . '-' . substr($UUID, 12, 4) . '-' . substr($UUID, 16, 4)  . '-' . substr($UUID, 20);    echo $UUID;?>

Borrowed from fico7489: https://stackoverflow.com/a/33484855/4195825

And then you can send that to Java where you can create a UUID object using fromtString().


UUID is not a special java format. It is the Universal Unique Identifier.

A universally unique identifier (UUID) is an identifier standard used in software construction. A UUID is simply a 128-bit value.

What happen is that the conversion from the 128 bit value to a human readable version of the same value converting it to a string follow generally some conventions.

Basically the number is converted to the better human readable hexadecimal format with some hyphen to separate block of bits.


From a performance perspective you can use the several times the substr_replace function, instead of creating an array of strings using substr and applying implode to it.