3v4l.org

run code in 300+ PHP versions simultaneously
<? /** * Given a Hex IP Address, this script will convert * and display Decimal and Binary representations of * the IP Address. * * This script was created for a one time personal use. * It works for well for valid hex addresses, but may return * unexpected results for invalid hex input (non hex characters, * too many/few hex digits, etc). * * @author Josh Grochowski (josh@kastang.com) * */ //determines if the input is through a command line, or web browser if(isset($argv[1])) { $HEX_IP = $argv[1]; } else if(isset($_GET["hexip"])) { $HEX_IP = $_GET["hexip"]; } else { throw new Exception("No HEX Input through CLI or GET."); } $HEX_IP = str_split($HEX_IP, 2); $BIN_IP = ''; foreach($HEX_IP as $h) { $d = base_convert($h, 16, 2); //Pads the Binary string with 0's if length is less then 8. if(strlen($d) < 8) { $len = strlen($d); while($len < 8) { $d = '0'.$d; $len++; } } $BIN_IP .= $d; } //Displays the length of the Binary string and shows the IP in Binary Notation echo 'Binary Length: '. strlen($BIN_IP)."\n"; echo $BIN_IP."\n\n"; //Splits the string into 4, 8 bit segments. $BIN_IP = str_split($BIN_IP, 8); //Converts each Binary block to a decimal and forms the IP address. echo 'Decimal IP: '; $ip = ''; foreach($BIN_IP as $x) { $ip .= base_convert($x, 2, 10).'.'; } //Displays the IP Address in Decimal format. echo substr($ip, 0, -1)."\n";
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.32, 7.1.26 - 7.1.33, 7.2.17 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
<? /** * Given a Hex IP Address, this script will convert * and display Decimal and Binary representations of * the IP Address. * * This script was created for a one time personal use. * It works for well for valid hex addresses, but may return * unexpected results for invalid hex input (non hex characters, * too many/few hex digits, etc). * * @author Josh Grochowski (josh@kastang.com) * */ //determines if the input is through a command line, or web browser if(isset($argv[1])) { $HEX_IP = $argv[1]; } else if(isset($_GET["hexip"])) { $HEX_IP = $_GET["hexip"]; } else { throw new Exception("No HEX Input through CLI or GET."); } $HEX_IP = str_split($HEX_IP, 2); $BIN_IP = ''; foreach($HEX_IP as $h) { $d = base_convert($h, 16, 2); //Pads the Binary string with 0's if length is less then 8. if(strlen($d) < 8) { $len = strlen($d); while($len < 8) { $d = '0'.$d; $len++; } } $BIN_IP .= $d; } //Displays the length of the Binary string and shows the IP in Binary Notation echo 'Binary Length: '. strlen($BIN_IP)."\n"; echo $BIN_IP."\n\n"; //Splits the string into 4, 8 bit segments. $BIN_IP = str_split($BIN_IP, 8); //Converts each Binary block to a decimal and forms the IP address. echo 'Decimal IP: '; $ip = ''; foreach($BIN_IP as $x) { $ip .= base_convert($x, 2, 10).'.'; } //Displays the IP Address in Decimal format. echo substr($ip, 0, -1)."\n";
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <? /** * Given a Hex IP Address, this script will convert * and display Decimal and Binary representations of * the IP Address. * * This script was created for a one time personal use. * It works for well for valid hex addresses, but may return * unexpected results for invalid hex input (non hex characters, * too many/few hex digits, etc). * * @author Josh Grochowski (josh@kastang.com) * */ //determines if the input is through a command line, or web browser if(isset($argv[1])) { $HEX_IP = $argv[1]; } else if(isset($_GET["hexip"])) { $HEX_IP = $_GET["hexip"]; } else { throw new Exception("No HEX Input through CLI or GET."); } $HEX_IP = str_split($HEX_IP, 2); $BIN_IP = ''; foreach($HEX_IP as $h) { $d = base_convert($h, 16, 2); //Pads the Binary string with 0's if length is less then 8. if(strlen($d) < 8) { $len = strlen($d); while($len < 8) { $d = '0'.$d; $len++; } } $BIN_IP .= $d; } //Displays the length of the Binary string and shows the IP in Binary Notation echo 'Binary Length: '. strlen($BIN_IP)."\n"; echo $BIN_IP."\n\n"; //Splits the string into 4, 8 bit segments. $BIN_IP = str_split($BIN_IP, 8); //Converts each Binary block to a decimal and forms the IP address. echo 'Decimal IP: '; $ip = ''; foreach($BIN_IP as $x) { $ip .= base_convert($x, 2, 10).'.'; } //Displays the IP Address in Decimal format. echo substr($ip, 0, -1)."\n";
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.32 - 7.3.33, 7.4.33, 8.0.13
Fatal error: Uncaught Exception: No HEX Input through CLI or GET. in /in/9NkJU:22 Stack trace: #0 {main} thrown in /in/9NkJU on line 22
Process exited with code 255.
Output for 5.4.34 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Fatal error: Uncaught exception 'Exception' with message 'No HEX Input through CLI or GET.' in /in/9NkJU:22 Stack trace: #0 {main} thrown in /in/9NkJU on line 22
Process exited with code 255.

preferences:
270.07 ms | 402 KiB | 353 Q