本文介绍了如何在 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 中获取字符串的十六进制转储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!