3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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); ?>
Output for 4.4.8 - 4.4.9, 5.2.4 - 5.6.28, 7.0.0 - 7.1.0
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 hhvm-3.10.0 - 3.12.0
Warning: Invalid argument: Type 0: unknown format code in /in/jojeZ on line 32 Warning: Invalid argument: 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 41
Output for 4.3.2 - 4.4.7, 5.0.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) { }