我如何获得字符串的十六进制转储PHP? [英] How can I get a hex dump of a string in PHP?
本文介绍了我如何获得字符串的十六进制转储PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在调查PHP5中的编码。有没有办法得到一个字符串的原始十六进制转储?即,字符串中每个字节(而不是字符)的十六进制表示形式?
I'm investigating encodings in PHP5. Is there some way to get a raw hex dump of a string? i.e. a hex representation of each of the bytes (not characters) in a string?
推荐答案
echo bin2hex($string);
或:
for ($i = 0; $i < strlen($string); $i++) {
echo str_pad(dechex(ord($string[$i])), 2, '0', STR_PAD_LEFT);
}
$ string
包含输入的变量。
这篇关于我如何获得字符串的十六进制转储PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文