- base_convert: documentation ( source)
- implode: documentation ( source)
- strtoupper: documentation ( source)
- str_pad: documentation ( source)
<?php
function _hex2bin($hex)
{
$hex = strtoupper($hex);
$hexLen = strlen($hex);
$bin = [];
for ($i = 0; $i < $hexLen; $i++) {
$char = $hex[$i];
$bin[] = str_pad(base_convert($char, 16, 2), 4, '0', STR_PAD_LEFT);
}
return implode("", $bin);
}
echo _hex2bin("152F302436152F302435152F302434152F302433152F302433");