duanli9569 2016-01-25 17:25 采纳率: 100%
浏览 402

如何将PHP十六进制数组转换为ascii? \ X76 \ X52 \ X9

How can I convert a PHP hex array, to ascii? Ex. if I have this string:

$var1="\x76\x52\x9\x3a\x5b\x79";

When I echo it, it appears right, but I'd like to convert it to ascii in the program, so I can do further processing on it & use it further in the script.

  • 写回答

2条回答 默认 最新

  • dongxie548548 2016-01-25 17:37
    关注

    You can try this code

    <?php
     $var1 = '\x76\x52\x9\x3a\x5b\x79';
    
    echo hexa_string($var1);
    
    function hexa_string($hex_str)
    {
    $string='';
    for ($i=0; $i < strlen($hex_str)-1; $i+=2)
    {
        $string .= chr(hexdec($hex_str[$i].$hex_str[$i+1]));
    }
    return $string;
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统