3v4l.org

run code in 300+ PHP versions simultaneously
<?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, $testPart); //echo strToHex($testPart) . "<br>\n"; } $packed = pack('H*', $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.0 - 4.4.1, 4.4.3 - 4.4.9, 5.0.0 - 5.0.2, 5.0.5, 5.1.0 - 5.1.1, 5.1.3 - 5.1.6, 5.2.0 - 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, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Warning: pack(): 7 arguments unused in /in/8YLsZ on line 32 string(2) "��" array(1) { [1]=> string(4) "ffff" } ffff
Output for 4.4.2, 5.1.2
Warning: pack(): 7 arguments unused in /in/8YLsZ on line 32 string(2) "��" array(1) { [1]=> string(5) "ffff0" } ffff0
Output for 4.3.10, 5.0.3 - 5.0.4
Warning: pack(): 7 arguments unused in /in/8YLsZ on line 32 Warning: unpack(): Type H: outside of string in /in/8YLsZ on line 33 string(2) "��" array(1) { [1]=> string(4) "ffff" } ffff
Output for 4.3.2 - 4.3.4
Warning: pack(): 7 arguments unused in /in/8YLsZ on line 32 string(2) "��" array(1) { [""]=> string(4) "ffff" } ffff
Output for 4.3.0 - 4.3.1
Warning: pack() [http://www.php.net/function.pack]: 7 arguments unused in /in/8YLsZ on line 32 string(2) "��" array(1) { [""]=> string(4) "ffff" } ffff

preferences:
311.34 ms | 401 KiB | 456 Q