@ 2014-01-30T14:26:36Z <?php
function strToHex($string)
{
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function hexToStr($hex)
{
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
$test = "ffff:eeee:dddd:cccc:bbbb:aaaa:9999:8888";
$testParts = explode(':', $test);
$testHex = array();
foreach($testParts as $testPart){
array_push($testHex, strToHex($testPart));
//echo strToHex($testPart) . "<br>\n";
}
$packed = pack('0\xH*', $testParts[0], $testParts[1], $testParts[2], $testParts[3], $testParts[4], $testParts[5], $testParts[6], $testParts[7]);
$unpacked = unpack('0\xH*', $packed);
$unpackedString = array();
//var_dump($testParts);
//var_dump($testHex);
var_dump($packed);
var_dump($unpacked);
foreach($unpacked as $unpack){
array_push($unpackedString, $unpack);
}
echo implode(':', $unpackedString);
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught ValueError: Type 0: unknown format code in /in/jojeZ:32
Stack trace:
#0 /in/jojeZ(32): pack('0\\xH*', 'ffff', 'eeee', 'dddd', 'cccc', 'bbbb', 'aaaa', '9999', '8888')
#1 {main}
thrown in /in/jojeZ on line 32
Process exited with code 255 . Output for 4.4.8 - 4.4.9 , 5.2.4 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Warning: pack(): Type 0: unknown format code in /in/jojeZ on line 32
Warning: unpack(): Invalid format type 0 in /in/jojeZ on line 33
bool(false)
bool(false)
Warning: Invalid argument supplied for foreach() in /in/jojeZ on line 39
Output for 4.3.2 - 4.3.11 , 4.4.0 - 4.4.7 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.3 Warning: pack(): Type 0: unknown format code in /in/jojeZ on line 32
bool(false)
array(0) {
}
Output for 4.3.0 - 4.3.1 Warning: pack() [http://www.php.net/function.pack]: Type 0: unknown format code in /in/jojeZ on line 32
bool(false)
array(0) {
}
preferences:dark mode live preview
299.57 ms | 401 KiB | 460 Q