PHP Binary to Hex with leading zeros

后端 未结 3 1737
無奈伤痛
無奈伤痛 2021-01-23 04:58

I have the follow code:


Which works fine, and I get a valu

3条回答
  •  时光说笑
    2021-01-23 05:29

    Use str_pad() for that:

    // maximum number of chars is maximum number of words 
    // an integer consumes on your system
    $maxchars = PHP_INT_SIZE * 2; 
    $hex = str_pad($hex, $maxchars, "0", STR_PAD_LEFT);
    

提交回复
热议问题