PHP输出uniqueidentifier类型问题【在线等】

WBOY
Release: 2016-06-23 13:53:13
Original
927 people have browsed it

我用PHP查询SQL2005数据库里的某表时,表的ID数据类型是uniqueidentifier类型,我想把这列输出在页面上,请问有什么办法。在线等,谢谢。


回复讨论(解决方案)

他是 16 字节的二进制数据,读出来应该是个串
你给我看看,才好说怎么做
比如读出后保存在变量 $id 中
你就 echo base64_encode($id); 贴出结果

V+mLfrZqsEa+dAAJhxD9Yw==
我有你的方法输出后就是这个结果。

版主还在吗?帮我看看啊,我这就差这一点点关键的了。

$id = base64_decode('V+mLfrZqsEa+dAAJhxD9Yw==');echo join('-', unpack('H8a/H4b/H4d/H4e/H*f', $id));
Copy after login
57e98b7e-b66a-b046-be74-00098710fd63

对对,谢谢版主,能解释一下吗?我没看懂,麻烦了。

uniqueidentifier类型是一个32字节长的二进制数据
一般显示为5节十六进制数(8,4,4,4,12)
将二进制数据转换成十六进制表示的方法有多种
这里我使用了 unpack 函数
转换时的格式串 H8a/H4b/H4d/H4e/H*f 的含义为
H8a 取8个字节转换成十六进制表示,放在键名 a 中
H4b 取4个字节转换成十六进制表示,放在键名 b 中
H4d 取4个字节转换成十六进制表示,放在键名 d 中
H4e 取4个字节转换成十六进制表示,放在键名 e 中
H*f 剩余的转成十六进制表示,放在键名 f 中
/ 是分节符


谢谢!十分感谢。

利用bin2hex()函数输出即可

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!