Is there a more effective, simplified means of converting a "formatted" Java UUID - without dashes - to a Java compatible format - with dashes - in PHP, and ultimately: How would I do it?
I have code that already performs this action, but it seems unprofessional and I feel that it could probably be done more effectively.
[... PHP code ...]
$uuido = $json['id'];
$uuidx = array();
$uuidx[0] = substr( $uuido, 0, 8 );
$uuidx[1] = substr( $uuido, 8, 4 );
$uuidx[2] = substr( $uuido, 12, 4);
$uuidx[3] = substr( $uuido, 16, 4);
$uuidx[4] = substr( $uuido, 20, 12);
$uuid = implode( "-", $uuidx );
[... PHP code ...]
Input: f9e113324bd449809b98b0925eac3141
Output: f9e11332-4bd4-4980-9b98-b0925eac3141
The data from $json['id']
is called from the following Mojang Profile API using the file_get_contents( $url )
function combined with a json_decode( $file )
, which could alternatively be done through cURL - but since it would eventually be requesting anything up to 2048 profiles at once, I figured it would become slow.
I do have my code in use, and public, through the following ProjectRogue Server Ping API, which usually contains a list of online players.
Note: There are several questions related to this, but none apply to PHP as far as I am aware. I have looked.
I mention Java UUID as the parsed output should effectively translate to a Player UUID for use in a Java-Based plugin for Spigot or Craftbukkit after 1.7.X.