3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Author: David S. Tufts * Company: Rocketwood.LLC * www.rocketwood.com * Date: 05/25/2003 * Usage: * <img src="/barcode.php?text=testing" alt="testing" /> */ // Get pararameters that are passed in through $_GET or set to the default value $text = (isset($_GET["text"])?$_GET["text"]:"0"); $size = (isset($_GET["size"])?$_GET["size"]:"20"); $orientation = (isset($_GET["orientation"])?$_GET["orientation"]:"horizontal"); $code_type = (isset($_GET["codetype"])?$_GET["codetype"]:"code128"); $code_string = ""; // Translate the $text into barcode the correct $code_type if ( in_array(strtolower($code_type), array("code128", "code128b")) ) { $chksum = 104; // Must not change order of array elements as the checksum depends on the array's key to validate final code $code_array = array(" "=>"212222","!"=>"222122","\""=>"222221","#"=>"121223","$"=>"121322","%"=>"131222","&"=>"122213","'"=>"122312","("=>"132212",")"=>"221213","*"=>"221312","+"=>"231212",","=>"112232","-"=>"122132","."=>"122231","/"=>"113222","0"=>"123122","1"=>"123221","2"=>"223211","3"=>"221132","4"=>"221231","5"=>"213212","6"=>"223112","7"=>"312131","8"=>"311222","9"=>"321122",":"=>"321221",";"=>"312212","<"=>"322112","="=>"322211",">"=>"212123","?"=>"212321","@"=>"232121","A"=>"111323","B"=>"131123","C"=>"131321","D"=>"112313","E"=>"132113","F"=>"132311","G"=>"211313","H"=>"231113","I"=>"231311","J"=>"112133","K"=>"112331","L"=>"132131","M"=>"113123","N"=>"113321","O"=>"133121","P"=>"313121","Q"=>"211331","R"=>"231131","S"=>"213113","T"=>"213311","U"=>"213131","V"=>"311123","W"=>"311321","X"=>"331121","Y"=>"312113","Z"=>"312311","["=>"332111","\\"=>"314111","]"=>"221411","^"=>"431111","_"=>"111224","\`"=>"111422","a"=>"121124","b"=>"121421","c"=>"141122","d"=>"141221","e"=>"112214","f"=>"112412","g"=>"122114","h"=>"122411","i"=>"142112","j"=>"142211","k"=>"241211","l"=>"221114","m"=>"413111","n"=>"241112","o"=>"134111","p"=>"111242","q"=>"121142","r"=>"121241","s"=>"114212","t"=>"124112","u"=>"124211","v"=>"411212","w"=>"421112","x"=>"421211","y"=>"212141","z"=>"214121","{"=>"412121","|"=>"111143","}"=>"111341","~"=>"131141","DEL"=>"114113","FNC 3"=>"114311","FNC 2"=>"411113","SHIFT"=>"411311","CODE C"=>"113141","FNC 4"=>"114131","CODE A"=>"311141","FNC 1"=>"411131","Start A"=>"211412","Start B"=>"211214","Start C"=>"211232","Stop"=>"2331112"); $code_keys = array_keys($code_array); $code_values = array_flip($code_keys); for ( $X = 1; $X <= strlen($text); $X++ ) { $activeKey = substr( $text, ($X-1), 1); $code_string .= $code_array[$activeKey]; $chksum=($chksum + ($code_values[$activeKey] * $X)); } $code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]]; $code_string = "211214" . $code_string . "2331112"; } elseif ( strtolower($code_type) == "code128a" ) { $chksum = 103; $text = strtoupper($text); // Code 128A doesn't support lower case // Must not change order of array elements as the checksum depends on the array's key to validate final code $code_array = array(" "=>"212222","!"=>"222122","\""=>"222221","#"=>"121223","$"=>"121322","%"=>"131222","&"=>"122213","'"=>"122312","("=>"132212",")"=>"221213","*"=>"221312","+"=>"231212",","=>"112232","-"=>"122132","."=>"122231","/"=>"113222","0"=>"123122","1"=>"123221","2"=>"223211","3"=>"221132","4"=>"221231","5"=>"213212","6"=>"223112","7"=>"312131","8"=>"311222","9"=>"321122",":"=>"321221",";"=>"312212","<"=>"322112","="=>"322211",">"=>"212123","?"=>"212321","@"=>"232121","A"=>"111323","B"=>"131123","C"=>"131321","D"=>"112313","E"=>"132113","F"=>"132311","G"=>"211313","H"=>"231113","I"=>"231311","J"=>"112133","K"=>"112331","L"=>"132131","M"=>"113123","N"=>"113321","O"=>"133121","P"=>"313121","Q"=>"211331","R"=>"231131","S"=>"213113","T"=>"213311","U"=>"213131","V"=>"311123","W"=>"311321","X"=>"331121","Y"=>"312113","Z"=>"312311","["=>"332111","\\"=>"314111","]"=>"221411","^"=>"431111","_"=>"111224","NUL"=>"111422","SOH"=>"121124","STX"=>"121421","ETX"=>"141122","EOT"=>"141221","ENQ"=>"112214","ACK"=>"112412","BEL"=>"122114","BS"=>"122411","HT"=>"142112","LF"=>"142211","VT"=>"241211","FF"=>"221114","CR"=>"413111","SO"=>"241112","SI"=>"134111","DLE"=>"111242","DC1"=>"121142","DC2"=>"121241","DC3"=>"114212","DC4"=>"124112","NAK"=>"124211","SYN"=>"411212","ETB"=>"421112","CAN"=>"421211","EM"=>"212141","SUB"=>"214121","ESC"=>"412121","FS"=>"111143","GS"=>"111341","RS"=>"131141","US"=>"114113","FNC 3"=>"114311","FNC 2"=>"411113","SHIFT"=>"411311","CODE C"=>"113141","CODE B"=>"114131","FNC 4"=>"311141","FNC 1"=>"411131","Start A"=>"211412","Start B"=>"211214","Start C"=>"211232","Stop"=>"2331112"); $code_keys = array_keys($code_array); $code_values = array_flip($code_keys); for ( $X = 1; $X <= strlen($text); $X++ ) { $activeKey = substr( $text, ($X-1), 1); $code_string .= $code_array[$activeKey]; $chksum=($chksum + ($code_values[$activeKey] * $X)); } $code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]]; $code_string = "211412" . $code_string . "2331112"; } elseif ( strtolower($code_type) == "code39" ) { $code_array = array("0"=>"111221211","1"=>"211211112","2"=>"112211112","3"=>"212211111","4"=>"111221112","5"=>"211221111","6"=>"112221111","7"=>"111211212","8"=>"211211211","9"=>"112211211","A"=>"211112112","B"=>"112112112","C"=>"212112111","D"=>"111122112","E"=>"211122111","F"=>"112122111","G"=>"111112212","H"=>"211112211","I"=>"112112211","J"=>"111122211","K"=>"211111122","L"=>"112111122","M"=>"212111121","N"=>"111121122","O"=>"211121121","P"=>"112121121","Q"=>"111111222","R"=>"211111221","S"=>"112111221","T"=>"111121221","U"=>"221111112","V"=>"122111112","W"=>"222111111","X"=>"121121112","Y"=>"221121111","Z"=>"122121111","-"=>"121111212","."=>"221111211"," "=>"122111211","$"=>"121212111","/"=>"121211121","+"=>"121112121","%"=>"111212121","*"=>"121121211"); // Convert to uppercase $upper_text = strtoupper($text); for ( $X = 1; $X<=strlen($upper_text); $X++ ) { $code_string .= $code_array[substr( $upper_text, ($X-1), 1)] . "1"; } $code_string = "1211212111" . $code_string . "121121211"; } elseif ( strtolower($code_type) == "code25" ) { $code_array1 = array("1","2","3","4","5","6","7","8","9","0"); $code_array2 = array("3-1-1-1-3","1-3-1-1-3","3-3-1-1-1","1-1-3-1-3","3-1-3-1-1","1-3-3-1-1","1-1-1-3-3","3-1-1-3-1","1-3-1-3-1","1-1-3-3-1"); for ( $X = 1; $X <= strlen($text); $X++ ) { for ( $Y = 0; $Y < count($code_array1); $Y++ ) { if ( substr($text, ($X-1), 1) == $code_array1[$Y] ) $temp[$X] = $code_array2[$Y]; } } for ( $X=1; $X<=strlen($text); $X+=2 ) { if ( isset($temp[$X]) && isset($temp[($X + 1)]) ) { $temp1 = explode( "-", $temp[$X] ); $temp2 = explode( "-", $temp[($X + 1)] ); for ( $Y = 0; $Y < count($temp1); $Y++ ) $code_string .= $temp1[$Y] . $temp2[$Y]; } } $code_string = "1111" . $code_string . "311"; } elseif ( strtolower($code_type) == "codabar" ) { $code_array1 = array("1","2","3","4","5","6","7","8","9","0","-","$",":","/",".","+","A","B","C","D"); $code_array2 = array("1111221","1112112","2211111","1121121","2111121","1211112","1211211","1221111","2112111","1111122","1112211","1122111","2111212","2121112","2121211","1121212","1122121","1212112","1112122","1112221"); // Convert to uppercase $upper_text = strtoupper($text); for ( $X = 1; $X<=strlen($upper_text); $X++ ) { for ( $Y = 0; $Y<count($code_array1); $Y++ ) { if ( substr($upper_text, ($X-1), 1) == $code_array1[$Y] ) $code_string .= $code_array2[$Y] . "1"; } } $code_string = "11221211" . $code_string . "1122121"; } // Pad the edges of the barcode $code_length = 20; for ( $i=1; $i <= strlen($code_string); $i++ ) $code_length = $code_length + (integer)(substr($code_string,($i-1),1)); if ( strtolower($orientation) == "horizontal" ) { $img_width = $code_length; $img_height = $size; } else { $img_width = $size; $img_height = $code_length; } $image = imagecreate($img_width, $img_height); $black = imagecolorallocate ($image, 0, 0, 0); $white = imagecolorallocate ($image, 255, 255, 255); imagefill( $image, 0, 0, $white ); $location = 10; for ( $position = 1 ; $position <= strlen($code_string); $position++ ) { $cur_size = $location + ( substr($code_string, ($position-1), 1) ); if ( strtolower($orientation) == "horizontal" ) imagefilledrectangle( $image, $location, 0, $cur_size, $img_height, ($position % 2 == 0 ? $white : $black) ); else imagefilledrectangle( $image, 0, $location, $img_width, $cur_size, ($position % 2 == 0 ? $white : $black) ); $location = $cur_size; } // Draw barcode to the screen header ('Content-type: image/png'); imagepng($image); imagedestroy($image); ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0100.01418.43
8.3.50.0140.00722.17
8.3.40.0060.00918.96
8.3.30.0150.00019.03
8.3.20.0040.00420.46
8.3.10.0080.00023.35
8.3.00.0080.00019.91
8.2.180.0070.01518.41
8.2.170.0040.01122.96
8.2.160.0000.01420.66
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0080.00019.51
8.2.120.0000.00826.35
8.2.110.0060.00322.25
8.2.100.0120.00018.16
8.2.90.0040.00419.30
8.2.80.0030.00617.97
8.2.70.0060.00317.88
8.2.60.0060.00318.18
8.2.50.0040.00418.07
8.2.40.0040.00421.01
8.2.30.0050.00520.86
8.2.20.0080.00018.09
8.2.10.0050.00318.28
8.2.00.0000.00718.17
8.1.280.0070.00725.92
8.1.270.0000.00919.30
8.1.260.0060.00326.35
8.1.250.0050.00328.09
8.1.240.0060.00320.90
8.1.230.0070.00419.41
8.1.220.0060.00318.02
8.1.210.0040.00418.77
8.1.200.0030.00717.61
8.1.190.0000.00817.89
8.1.180.0040.00418.10
8.1.170.0000.00918.76
8.1.160.0060.00320.93
8.1.150.0070.00018.99
8.1.140.0080.00019.76
8.1.130.0000.00717.82
8.1.120.0070.00017.66
8.1.110.0040.00417.63
8.1.100.0040.00417.70
8.1.90.0090.00317.53
8.1.80.0080.00017.60
8.1.70.0000.00717.64
8.1.60.0060.00317.68
8.1.50.0040.00417.62
8.1.40.0040.00417.68
8.1.30.0030.00617.84
8.1.20.0030.00617.81
8.1.10.0060.00317.65
8.1.00.0030.00917.70
8.0.300.0060.00318.77
8.0.290.0080.00017.13
8.0.280.0040.00418.62
8.0.270.0030.00617.48
8.0.260.0030.00317.44
8.0.250.0030.00317.09
8.0.240.0070.00017.16
8.0.230.0080.00017.21
8.0.220.0050.00317.05
8.0.210.0000.00717.14
8.0.200.0060.00017.21
8.0.190.0080.00017.07
8.0.180.0000.00817.02
8.0.170.0050.00317.23
8.0.160.0020.00517.10
8.0.150.0040.00417.11
8.0.140.0000.00817.01
8.0.130.0030.00313.54
8.0.120.0000.00817.04
8.0.110.0030.00617.15
8.0.100.0060.00317.14
8.0.90.0080.00017.18
8.0.80.0030.01317.02
8.0.70.0080.00017.17
8.0.60.0040.00417.11
8.0.50.0050.00216.96
8.0.30.0090.01017.39
8.0.20.0120.00917.40
8.0.10.0000.00717.32
8.0.00.0100.00816.81
7.4.330.0050.00016.79
7.4.320.0000.00716.66
7.4.300.0000.00716.67
7.4.290.0070.00016.68
7.4.280.0030.00516.64
7.4.270.0070.00016.67
7.4.260.0070.00016.79
7.4.250.0000.00816.71
7.4.240.0040.00416.66
7.4.230.0070.00016.88
7.4.220.0090.00916.68
7.4.210.0080.01116.65
7.4.200.0000.00716.81
7.4.160.0130.00316.69
7.4.150.0090.00917.40
7.4.140.0100.01017.86
7.4.130.0120.00716.75
7.4.120.0090.00816.80
7.4.110.0140.00516.61
7.4.100.0060.01116.95
7.4.90.0110.00816.88
7.4.80.0150.00619.39
7.4.70.0170.00016.53
7.4.60.0070.01816.80
7.4.50.0090.00916.73
7.4.40.0090.00816.85
7.4.30.0090.00916.84
7.4.10.0140.00415.32
7.4.00.0060.01215.16
7.3.330.0000.00513.48
7.3.320.0060.00013.41
7.3.310.0080.00016.64
7.3.300.0080.00016.42
7.3.290.0040.00416.47
7.3.280.0080.00716.57
7.3.270.0140.00417.40
7.3.260.0030.01516.54
7.3.250.0140.00716.54
7.3.240.0120.00816.65
7.3.230.0140.00316.64
7.3.210.0030.01616.65
7.3.200.0080.00916.63
7.3.190.0060.01216.79
7.3.180.0090.00616.55
7.3.170.0120.00916.79
7.3.160.0120.00616.68
7.3.130.0100.01014.90
7.3.120.0070.01115.00
7.3.110.0070.01115.10
7.3.100.0130.00315.13
7.3.90.0090.00615.04
7.3.80.0000.01115.20
7.3.70.0040.01114.81
7.3.60.0040.01415.16
7.3.50.0030.00914.78
7.3.40.0040.01115.06
7.3.30.0090.00615.11
7.3.20.0040.01116.39
7.3.10.0060.00916.78
7.3.00.0040.01416.48
7.2.330.0060.01216.70
7.2.320.0120.00916.61
7.2.310.0030.01416.77
7.2.300.0120.00617.02
7.2.290.0090.00916.88
7.2.260.0070.01015.16
7.2.250.0150.00415.47
7.2.240.0000.01515.41
7.2.230.0110.00715.34
7.2.220.0070.00715.20
7.2.210.0000.01215.33
7.2.200.0110.00715.03
7.2.190.0070.01015.12
7.2.180.0030.00615.46
7.2.170.0040.01115.32
7.2.160.0040.01115.27
7.2.150.0000.01117.11
7.2.140.0050.00516.95
7.2.130.0050.00516.97
7.2.120.0000.01417.00
7.2.110.0090.00616.76
7.2.100.0030.01316.98
7.2.90.0000.01017.20
7.2.80.0100.00717.08
7.2.70.0070.00717.00
7.2.60.0070.00716.74
7.2.50.0040.01117.07
7.2.40.0060.00617.11
7.2.30.0100.00017.01
7.2.20.0060.00617.10
7.2.10.0070.01016.62
7.2.00.0080.00818.15
7.1.330.0070.00715.74
7.1.320.0090.00615.77
7.1.310.0030.00915.67
7.1.300.0090.00615.81
7.1.290.0070.00315.59
7.1.280.0040.00715.94
7.1.270.0070.01115.74
7.1.260.0000.01015.71
7.1.250.0040.01415.91
7.1.240.0000.01115.99
7.1.230.0080.00015.75
7.1.220.0030.00915.63
7.1.210.0000.00815.91
7.1.200.0060.01015.86
7.1.190.0060.00615.97
7.1.180.0030.00915.61
7.1.170.0040.00815.96
7.1.160.0070.00715.61
7.1.150.0040.00415.63
7.1.140.0030.00715.87
7.1.130.0060.00915.85
7.1.120.0080.00815.77
7.1.110.0030.00615.78
7.1.100.0040.00916.93
7.1.90.0070.01015.80
7.1.80.0040.00815.83
7.1.70.0060.00616.59
7.1.60.0100.00917.65
7.1.50.0110.00916.47
7.1.40.0000.01415.92
7.1.30.0080.00615.92
7.1.20.0120.00315.95
7.1.10.0040.00715.94
7.1.00.0060.04019.11
7.0.330.0100.00715.21
7.0.320.0000.01215.49
7.0.310.0000.01415.39
7.0.300.0000.01315.45
7.0.290.0030.00915.30
7.0.280.0060.00915.40
7.0.270.0070.01015.63
7.0.260.0000.01215.18
7.0.250.0030.00615.56
7.0.240.0030.00615.36
7.0.230.0060.01015.50
7.0.220.0040.00815.11
7.0.210.0030.00715.53
7.0.200.0040.00716.14
7.0.190.0070.00415.49
7.0.180.0040.01115.66
7.0.170.0100.00615.33
7.0.160.0090.00615.48
7.0.150.0070.00415.21
7.0.140.0070.00415.55
7.0.130.0040.01115.49
7.0.120.0100.00315.41
7.0.110.0040.00815.43
7.0.100.0090.02817.75
7.0.90.0100.02717.81
7.0.80.0070.02917.77
7.0.70.0060.04317.75
7.0.60.0070.04417.68
7.0.50.0070.04718.04
7.0.40.0170.03816.84
7.0.30.0100.03716.68
7.0.20.0070.04016.88
7.0.10.0030.04016.73
7.0.00.0100.04016.81
5.6.400.0030.00614.41
5.6.390.0030.01014.55
5.6.380.0030.00914.32
5.6.370.0110.00714.45
5.6.360.0030.00614.66
5.6.350.0110.00814.50
5.6.340.0030.00614.68
5.6.330.0000.01214.69
5.6.320.0040.01114.64
5.6.310.0090.00614.32
5.6.300.0030.01014.46
5.6.290.0120.00314.65
5.6.280.0040.03017.99
5.6.270.0040.01114.67
5.6.260.0000.00914.26
5.6.250.0030.04417.60
5.6.240.0070.04217.82
5.6.230.0080.04317.55
5.6.220.0020.04417.71
5.6.210.0070.04817.63
5.6.200.0070.05317.79
5.6.190.0100.04017.84
5.6.180.0070.04317.90
5.6.170.0020.05017.86
5.6.160.0110.02317.99
5.6.150.0090.03917.86
5.6.140.0020.02817.84
5.6.130.0090.03817.89
5.6.120.0050.04817.76
5.6.110.0110.03417.68
5.6.100.0120.04217.72
5.6.90.0050.04517.91
5.6.80.0050.02717.40
5.6.70.0000.04417.52
5.6.60.0080.03817.35
5.6.50.0070.02517.34
5.6.40.0060.03717.66
5.6.30.0030.04817.46
5.6.20.0050.02817.30
5.6.10.0050.03517.47
5.6.00.0080.03017.47
5.5.380.0080.03717.65
5.5.370.0000.03417.51
5.5.360.0070.04417.50
5.5.350.0100.02817.51
5.5.340.0050.03717.66
5.5.330.0110.04317.67
5.5.320.0070.04317.84
5.5.310.0080.04117.78
5.5.300.0030.04517.77
5.5.290.0050.04817.68
5.5.280.0070.02917.85
5.5.270.0020.04617.57
5.5.260.0050.04517.74
5.5.250.0030.03117.60
5.5.240.0060.03717.33
5.5.230.0070.02817.56
5.5.220.0100.03617.24
5.5.210.0070.02717.22
5.5.200.0020.03417.16
5.5.190.0050.03917.47
5.5.180.0090.04117.25
5.5.170.0030.01013.90
5.5.160.0070.04217.25
5.5.150.0030.04017.46
5.5.140.0070.04317.24
5.5.130.0050.04017.51
5.5.120.0050.04517.25
5.5.110.0050.02617.37
5.5.100.0080.03817.47
5.5.90.0080.03817.20
5.5.80.0090.04017.40
5.5.70.0070.04017.30
5.5.60.0060.04317.30
5.5.50.0110.03417.43
5.5.40.0070.02017.20
5.5.30.0030.04517.25
5.5.20.0070.02417.32
5.5.10.0070.04217.25
5.5.00.0110.03017.20

preferences:
53.12 ms | 401 KiB | 5 Q