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 git.master, git.master_jit, rfc.property-hooks
<? /** * 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";

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.79 ms | 404 KiB | 8 Q