如何在PHP中将Base64字符串解码为文本?

时间:2015-12-08 15:01:31

标签: php

需要将Base64编码的字符串(\ x代码)转换为普通的可读文本。

例如:

Convert "\x62\141\x73\145\x36\64\x5f\144\x65\143\x6f\144\x65"
to "base64_decode".

如何使用PHP执行此操作。感谢。

1 个答案:

答案 0 :(得分:2)

如何将x-code转换为文本:

$xCodes = '\x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65';
$result = preg_replace_callback("/(\\\\x)([0-9A-Fa-f]+)/u", function($matched) {
    return chr(hexdec($matched[2]));
}, $xCodes);

var_dump($result); // string(13) "base64_decode"