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('xH*', $testParts[0], $testParts[1], $testParts[2], $testParts[3], $testParts[4], $testParts[5], $testParts[6], $testParts[7]); $unpacked = unpack('H*', $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.3.5 - 4.3.9, 4.3.11 - 4.4.1, 4.4.3 - 5.0.2, 5.0.5 - 5.1.1, 5.1.3 - 5.6.28, 7.0.0 - 7.1.0
Warning: pack(): 7 arguments unused in /in/qfs4u on line 32 string(3) "��" array(1) { [1]=> string(6) "00ffff" } 00ffff
Output for hhvm-3.10.0 - 3.12.0
Warning: Invalid argument: 7 arguments unused in /in/qfs4u on line 32 string(3) "��" array(1) { [1]=> string(6) "00ffff" } 00ffff
Output for 4.4.2, 5.1.2
Warning: pack(): 7 arguments unused in /in/qfs4u on line 32 string(3) "��" array(1) { [1]=> string(7) "00ffff0" } 00ffff0
Output for 4.3.10, 5.0.3 - 5.0.4
Warning: pack(): 7 arguments unused in /in/qfs4u on line 32 Warning: unpack(): Type H: outside of string in /in/qfs4u on line 33 string(3) "��" array(1) { [1]=> string(6) "00ffff" } 00ffff
Output for 4.3.2 - 4.3.4
Warning: pack(): 7 arguments unused in /in/qfs4u on line 32 string(3) "��" array(1) { [""]=> string(6) "00ffff" } 00ffff
Output for 4.3.0 - 4.3.1
Warning: pack() [http://www.php.net/function.pack]: 7 arguments unused in /in/qfs4u on line 32 string(3) "��" array(1) { [""]=> string(6) "00ffff" } 00ffff