如何将文本转换为\ x代码? [英] How to convert text to \x codes?

查看:998
本文介绍了如何将文本转换为\ x代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将普通文本转换为\ x代码,例如\ x14 \x65\x60



例如:

 正常文本=base64_decode
转换为上述文本的\ x代码=\x62\141\x73\145\\ \\ x36 \64\x5f\144\x65\143\x6f\144\x65

如何做到这一点?

解决方案

PHP 5.3单行程:

<$ p $ b $ echo $'code> echo preg_replace_callback(/./,function($ matched){
return'\x'.dechex(ord($ matched [0]));
},'base64_decode');

输出 \x62\x61\x73\x65\ x36 \x34\x5f\x64\x65\x63\x6f\x64\x65


I want to convert normal text to \x codes for e.g \x14\x65\x60

For example :

normal text = "base64_decode"
converted \x codes for above text = "\x62\141\x73\145\x36\64\x5f\144\x65\143\x6f\144\x65"

How to do this? Thanks in advance.

解决方案

PHP 5.3 one-liner:

echo preg_replace_callback("/./", function($matched) {
    return '\x'.dechex(ord($matched[0]));
}, 'base64_decode');

Outputs \x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65

这篇关于如何将文本转换为\ x代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆