3 回答

TA貢獻1828條經驗 獲得超3個贊
對于那些最終來到這里并且只是在尋找(二進制)字符串的十六進制表示的人。
bin2hex("that's all you need");
# 74686174277320616c6c20796f75206e656564
hex2bin('74686174277320616c6c20796f75206e656564');
# that's all you need

TA貢獻1802條經驗 獲得超10個贊
function hexToStr($hex){
// Remove spaces if the hex string has spaces
$hex = str_replace(' ', '', $hex);
return hex2bin($hex);
}
// Test it
$hex = "53 44 43 30 30 32 30 30 30 31 37 33";
echo hexToStr($hex); // SDC002000173
/**
* Test Hex To string with PHP UNIT
* @param string $value
* @return
*/
public function testHexToString()
{
$string = 'SDC002000173';
$hex = "53 44 43 30 30 32 30 30 30 31 37 33";
$result = hexToStr($hex);
$this->assertEquals($result,$string);
}
- 3 回答
- 0 關注
- 2819 瀏覽
添加回答
舉報