如何将字符串编码为十六进制表示?

How to encode a string into hexadecimal representation?

这个编码是什么类型? "\x734\x6f\x72175\x3a4\x69\x6e3"

如何像上面那样编码 "storage:link" 字符串?

您的字符串是“存储:link”的十六进制和八进制表示形式的混合:

\x734\x6f\x72175\x3a4\x69\x6e3
  ^   ^   ^   ^   ^   ^   ^   ^   ^   ^   ^   ^
 hex oct hex hex oct oct oct hex oct hex hex oct

根据 this comment,您可以将二进制字符串转换为十六进制表示的文本,如下所示:

$hexStr = bin2hex("storage:link");       // 73746f726167653a6c696e6b
$hexStr = chunk_split($hexStr, 2, '\x'); // 73\x74\x6f\x72\x61\x67\x65\x3a\x6c\x69\x6e\x6b\x
$hexStr = '\x' . substr($hexStr, 0, -2); // \x73\x74\x6f\x72\x61\x67\x65\x3a\x6c\x69\x6e\x6b

最终输出将是:

\x73\x74\x6f\x72\x61\x67\x65\x3a\x6c\x69\x6e\x6b
  ^   ^   ^   ^   ^   ^   ^   ^   ^   ^   ^   ^
 hex hex hex hex hex hex hex hex hex hex hex hex