使用PHP将GUID转换为字节数组? [英] Convert GUID into Byte array using PHP?

查看:81
本文介绍了使用PHP将GUID转换为字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将系统生成的GUID转换为Byte [16]数组,然后将那些十进制值转换为十六进制值字符串。疯狂,我知道并且我比我尝试过的更有效的方法。

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!

我已经在此GUID上尝试过PHPs unpack()函数但似乎无法获得正确的格式。我已经尝试过c *,C *和所有其他可能的格式。

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.

这里是我开始使用的GUID:

Here's the GUID I'm starting with:

GUID:dwRhRSIjlGXhAAAAkuFQ0A

我要填充的Byte [16]数组应该看起来像这样:

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);

一旦获得此$ bytearray值,就可以轻松使用PHP的dechex()函数来转换每个将这些十进制值转换为相应的十六进制值。转换的最终结果应如下所示:

Once I get this $bytearray 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.

推荐答案

我不确定我是否真的得到了你想要的……你想要一个数组,其ID中包含chars的ASCCI代码的十六进制值,是我吗?

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]));
}

这篇关于使用PHP将GUID转换为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆