note 124463 added to function.hex2bin

From: Date: Tue, 03 Dec 2019 14:30:32 +0000
Subject: note 124463 added to function.hex2bin
Groups: php.notes 
Request: Send a blank email to php-notes+get-213375@lists.php.net to get a copy of this message
If you want to convert hex to GUID format (In my case, it was to convert GUID from MSSQL database) : <?php function hex2Guid($hex) { $hex = [ substr($hex, 0, 8), substr($hex, 8, 4), substr($hex, 12, 4), substr($hex, 16, 4), substr($hex, 20), ]; $order[0] = [6, 7, 4, 5, 2, 3, 0, 1]; $order[1] = [2, 3, 0, 1]; $order[2] = [2, 3, 0, 1]; $order[3] = [0, 1, 2, 3]; $order[4] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; $result = ""; for($num = 0; $num < count($order); $num++) { for($i = 0; $i < count($order[$num]); $i++) { $result .= $hex[$num][$order[$num][$i]]; } if($num != count($order) -1) { $result .= "-"; } } return strtoupper($result); } Example : echo hex2Guid("64d3938b7008cd4bad5ffe56755d163f"); // return 8B93D364-0870-4BCD-AD5F-FE56755D163F ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.168 (proxied: 77.136.42.227) ---- Manual Page -- http://php.net/manual/en/function.hex2bin.php Edit -- https://master.php.net/note/edit/124463 Del: integrated -- https://master.php.net/note/delete/124463/integrated Del: useless -- https://master.php.net/note/delete/124463/useless Del: bad code -- https://master.php.net/note/delete/124463/bad+code Del: spam -- https://master.php.net/note/delete/124463/spam Del: non-english -- https://master.php.net/note/delete/124463/non-english Del: in docs -- https://master.php.net/note/delete/124463/in+docs Del: other reasons-- https://master.php.net/note/delete/124463 Reject -- https://master.php.net/note/reject/124463 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213375) next »