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('H*', $testHex[0], $testHex[1], $testHex[2], $testHex[3], $testHex[4], $testHex[5], $testHex[6], $testHex[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
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: pack(): 7 arguments unused in /in/6BKAE on line 32 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [1]=> string(8) "66666666" } 66666666
Output for hhvm-3.10.0 - 3.12.0
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: Invalid argument: 7 arguments unused in /in/6BKAE on line 32 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [1]=> string(8) "66666666" } 66666666
Output for 4.4.2, 5.1.2
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: pack(): 7 arguments unused in /in/6BKAE on line 32 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [1]=> string(9) "666666660" } 666666660
Output for 4.3.10, 5.0.3 - 5.0.4
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: pack(): 7 arguments unused in /in/6BKAE on line 32 Warning: unpack(): Type H: outside of string in /in/6BKAE on line 33 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [1]=> string(8) "66666666" } 66666666
Output for 4.3.2 - 4.3.4
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: pack(): 7 arguments unused in /in/6BKAE on line 32 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [""]=> string(8) "66666666" } 66666666
Output for 4.3.0 - 4.3.1
66666666<br> 65656565<br> 64646464<br> 63636363<br> 62626262<br> 61616161<br> 39393939<br> 38383838<br> Warning: pack() [http://www.php.net/function.pack]: 7 arguments unused in /in/6BKAE on line 32 array(8) { [0]=> string(4) "ffff" [1]=> string(4) "eeee" [2]=> string(4) "dddd" [3]=> string(4) "cccc" [4]=> string(4) "bbbb" [5]=> string(4) "aaaa" [6]=> string(4) "9999" [7]=> string(4) "8888" } array(8) { [0]=> string(8) "66666666" [1]=> string(8) "65656565" [2]=> string(8) "64646464" [3]=> string(8) "63636363" [4]=> string(8) "62626262" [5]=> string(8) "61616161" [6]=> string(8) "39393939" [7]=> string(8) "38383838" } string(4) "ffff" array(1) { [""]=> string(8) "66666666" } 66666666