字符串与16进制ASCII互转

    如对你有帮助,请我喝杯咖啡吧! 打赏

//字符串转16进制ASCII
$string = "cfg_power";
$arr1 = str_split($string, 1);
foreach($arr1 as $akey=>$aval){
    $arr1[$akey]="0x".bin2hex($aval);
}
var_dump($arr1);


//16进制ASCII转化为字符串
$arrs1 = array(0x63,0x66,0x67,0x5f,0x70,0x6f,0x77,0x65,0x72,0x62,0x79);

$myStr="";
for($i=0;isset($arrs1[$i]);$i++)
{
    $myStr.= chr($arrs1[$i]);
}
var_dump($myStr);