开发者

Convert GUID into Byte array using PHP?

I need to convert a system-generated GUID into a Byte[16] array and then convert those decimal values into a hex value string. Crazy, I know and I'm very open to a more efficient approach than the ones I've tried!

I've tried PHPs unpack() function on this GUID but can't seem to get the right format. I've tried c*, C* and all of the other possible formats.

Here's the GUID I'm starting with:

GUID: dwRhRSIjlGXhAAAAkuFQ0A

The Byte[16] array I'm trying to populate should look like this:

$bytearray = array(119,4,97,69,34,35,-108,101,-31,0,0,0,-110,-31,80,-48);

Once I get this $bytearray开发者_如何学Python value, I can easily use PHPs dechex() function to convert each of these decimal values into their corresponding hex values. The end result of this conversion should look like this:

DEC: HEX
119: 77
4: 4
97: 61
69: 45
34: 22
35: 23
-108: 94
101: 65
-31: E1
0: 00
0: 00
0: 00
-110: 92
-31: E1
80: 50
-48: D0

Again, any suggestions are greatly appreciated.


I'm not sure I really get what you want… You want an array with the hex value of the ASCCI code of the chars within you ID, am I right?

$str = "dwRhRSIjlGXhAAAAkuFQ0A";
$bytes = array();

for($i=0,$l = strlen($str);$i<$l;$i++)
{
    $bytes[] = dechex(ord($str[$i]));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜