如何将字符串' Hello world'转换为'\\ x48 \ x65 \ x6c \ x6c \ x6f \ x20 \ x57 \ x6f \ x72 \ x6c \ x64 \ x21'< / strong>使用php?
谢谢!
答案 0 :(得分:3)
应该工作
function strhex($string) {
$hexstr = unpack('H*', $string);
return array_shift($hexstr);
}
更新
所需代码下方的代码
function strtohex($string)
{
$string = str_split($string);
foreach($string as &$char)
$char = "\x".dechex(ord($char));
return implode('',$string);
}
print strtohex("[0-9A-Za-z\+/=]*");