3v4l.org

run code in 300+ PHP versions simultaneously
<?php function c_substr($string, $from, $length = null){ preg_match_all('/[x80-xff]?./', $string, $match); if(is_null($length)){ $result = implode('', array_slice($match[0], $from)); }else{ $result = implode('', array_slice($match[0], $from, $length)); } return $result; } $str = "zhon华人min共和guo"; $from = 3; $length = 7; echo(cut_str($str, $length)); function cut_str($sourcestr,$cutlength) { $returnstr=''; $i=0; $n=0; $str_length=strlen($sourcestr);//字符串的字节数 while (($n<$cutlength) and ($i<=$str_length)) { $temp_str=substr($sourcestr,$i,1); $ascnum=Ord($temp_str);//得到字符串中第$i位字符的ascii码 if ($ascnum>=224) //如果ASCII位高与224, { $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范,将3个连续的字符计为单个字符 $i=$i+3; //实际Byte计为3 $n++; //字串长度计1 } elseif ($ascnum>=192) //如果ASCII位高与192, { $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范,将2个连续的字符计为单个字符 $i=$i+2; //实际Byte计为2 $n++; //字串长度计1 } elseif ($ascnum>=65 && $ascnum<=90) //如果是大写字母, { $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数仍计1个 $n++; //但考虑整体美观,大写字母计成一个高位字符 } else //其他情况下,包括小写字母和半角标点符号, { $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数计1个 $n=$n+0.5; //小写字母和半角标点等与半个高位字符宽... } } if ($str_length>$cutlength){ $returnstr = $returnstr . "...";//超过长度时在尾处加上省略号 } return $returnstr; }

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.40.0040.01118.72
8.3.30.0100.00320.21
8.3.20.0070.00020.41
8.3.10.0040.00422.09
8.3.00.0000.00822.36
8.2.170.0170.00322.96
8.2.160.0070.00720.35
8.2.150.0000.00824.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00420.66
8.2.110.0100.00322.25
8.2.100.0090.00319.51
8.2.90.0050.00319.09
8.2.80.0040.00419.25
8.2.70.0030.00617.50
8.2.60.0040.00417.80
8.2.50.0040.00418.07
8.2.40.0000.00918.34
8.2.30.0000.00719.52
8.2.20.0040.00417.80
8.2.10.0030.00617.71
8.2.00.0000.00817.75
8.1.270.0060.00323.99
8.1.260.0070.00026.35
8.1.250.0000.00828.09
8.1.240.0060.00323.75
8.1.230.0060.00619.16
8.1.220.0050.00317.74
8.1.210.0050.00318.77
8.1.200.0060.00317.23
8.1.190.0050.00317.42
8.1.180.0030.00518.10
8.1.170.0090.00018.55
8.1.160.0050.00218.91
8.1.150.0040.00418.72
8.1.140.0030.00517.39
8.1.130.0030.00517.85
8.1.120.0040.00417.51
8.1.110.0000.00717.46
8.1.100.0040.00417.49
8.1.90.0040.00317.48
8.1.80.0040.00317.45
8.1.70.0030.00317.47
8.1.60.0030.00517.60
8.1.50.0060.00317.44
8.1.40.0040.00417.57
8.1.30.0050.00317.62
8.1.20.0000.00917.64
8.1.10.0040.00417.46
8.1.00.0000.00717.38
8.0.300.0050.00318.77
8.0.290.0040.00417.05
8.0.280.0000.00818.34
8.0.270.0070.00017.18
8.0.260.0000.00716.89
8.0.250.0000.00717.00
8.0.240.0040.00416.87
8.0.230.0020.00516.90
8.0.220.0040.00416.89
8.0.210.0070.00016.83
8.0.200.0040.00416.84
8.0.190.0000.00817.02
8.0.180.0040.00416.98
8.0.170.0040.00417.00
8.0.160.0000.00716.82
8.0.150.0070.00016.88
8.0.140.0040.00416.91
8.0.130.0000.00513.27
8.0.120.0000.00716.85
8.0.110.0030.00516.83
8.0.100.0050.00216.79
8.0.90.0040.00416.81
8.0.80.0060.01016.93
8.0.70.0020.00516.98
8.0.60.0040.00416.82
8.0.50.0070.00016.86
8.0.30.0070.01217.02
8.0.20.0090.01017.41
8.0.10.0000.00716.91
8.0.00.0140.01016.91
7.4.330.0030.00316.84
7.4.320.0030.00316.42
7.4.300.0030.00316.66
7.4.290.0000.00716.59
7.4.280.0040.00416.45
7.4.270.0070.00016.52
7.4.260.0030.00313.40
7.4.250.0000.00816.47
7.4.240.0020.00616.52
7.4.230.0040.00416.62
7.4.220.0090.00916.51
7.4.210.0080.00716.54
7.4.200.0000.00716.71
7.4.190.0030.00316.70
7.4.160.0100.00616.53
7.4.150.0120.00617.40
7.4.140.0060.01417.86
7.4.130.0100.01016.56
7.4.120.0080.01216.45
7.4.110.0150.00316.50
7.4.100.0070.01116.56
7.4.90.0110.00716.48
7.4.80.0040.01419.39
7.4.70.0080.00816.61
7.4.60.0070.01016.59
7.4.50.0040.00416.74
7.4.40.0030.01322.77
7.4.30.0080.00816.57
7.4.00.0100.00315.10
7.3.330.0030.00313.14
7.3.320.0020.00213.35
7.3.310.0070.00016.19
7.3.300.0000.00716.23
7.3.290.0070.00716.34
7.3.280.0040.01016.35
7.3.270.0130.01017.40
7.3.260.0110.01516.36
7.3.250.0100.00616.52
7.3.240.0140.00316.41
7.3.230.0060.01016.61
7.3.210.0060.01216.71
7.3.200.0070.01019.39
7.3.190.0030.01416.61
7.3.180.0060.01216.27
7.3.170.0060.00916.53
7.3.160.0120.00816.36
7.3.120.0070.00714.73
7.2.330.0090.00916.57
7.2.320.0110.00616.52
7.2.310.0100.00716.41
7.2.300.0070.01016.80
7.2.290.0060.01216.64
7.2.60.0090.00616.77
7.2.00.0030.01019.63
7.1.200.0000.01415.90
7.1.100.0070.00718.25
7.1.70.0000.01017.16
7.1.60.0130.01019.17
7.1.50.0070.01116.64
7.1.00.0030.06722.44
7.0.200.0000.00716.82
7.0.140.0030.06721.93
7.0.100.0130.08019.92
7.0.90.0030.04719.93
7.0.80.0500.07720.05
7.0.70.0370.07719.88
7.0.60.0530.07019.98
7.0.50.0300.07720.32
7.0.40.0100.07720.15
7.0.30.0030.09020.05
7.0.20.0100.08020.07
7.0.10.0070.07720.17
7.0.00.0130.06320.14
5.6.280.0100.06321.05
5.6.250.0070.05720.55
5.6.240.0170.07720.77
5.6.230.0000.04720.52
5.6.220.0000.09020.66
5.6.210.0030.09320.70
5.6.200.0070.08020.98
5.6.190.0070.09321.04
5.6.180.0070.08321.13
5.6.170.0070.07021.03
5.6.160.0270.06021.15
5.6.150.0030.08321.05
5.6.140.0130.07721.09
5.6.130.0000.09321.06
5.6.120.0100.06321.04
5.6.110.0000.05021.07
5.6.100.0100.07320.91
5.6.90.0230.08320.95
5.6.80.0100.04320.43
5.6.70.0130.05020.52
5.6.60.0000.05020.47
5.6.50.0030.04720.53
5.6.40.0130.06320.37
5.6.30.0130.07720.39
5.6.20.0100.03720.47
5.6.10.0070.08020.43
5.6.00.0200.03320.29
5.5.380.0030.07720.53
5.5.370.0070.08320.39
5.5.360.0100.07720.42
5.5.350.0170.07320.44
5.5.340.0070.08320.85
5.5.330.0100.07720.80
5.5.320.0100.08020.84
5.5.310.0100.04020.93
5.5.300.0000.07720.93
5.5.290.0070.06320.84
5.5.280.0100.06720.66
5.5.270.0100.08020.78
5.5.260.0030.07020.65
5.5.250.0000.07720.71
5.5.240.0070.06320.29
5.5.230.0070.08020.29
5.5.220.0030.05720.31
5.5.210.0170.06720.16
5.5.200.0130.06020.16
5.5.190.0100.05720.29
5.5.180.0100.08020.27
5.5.160.0170.06720.17
5.5.150.0070.06320.25
5.5.140.0130.07020.14
5.5.130.0070.08320.14
5.5.120.0000.05020.26
5.5.110.0030.06320.26
5.5.100.0100.04720.09
5.5.90.0170.06720.17
5.5.80.0100.06720.18
5.5.70.0100.07320.12
5.5.60.0130.04320.02
5.5.50.0000.06720.17
5.5.40.0030.08320.15
5.5.30.0130.07320.04
5.5.20.0030.07320.07
5.5.10.0070.04320.09
5.5.00.0100.07020.05
5.4.450.0030.05719.46
5.4.440.0130.08019.49
5.4.430.0100.08319.35
5.4.420.0070.08019.23
5.4.410.0030.07319.24
5.4.400.0130.06719.03
5.4.390.0100.07319.05
5.4.380.0070.07719.05
5.4.370.0070.06319.03
5.4.360.0100.06318.93
5.4.350.0070.07719.03
5.4.340.0030.04719.21
5.4.320.0030.09319.05
5.4.310.0070.05318.88
5.4.300.0070.05318.84
5.4.290.0070.07018.90
5.4.280.0100.07719.12
5.4.270.0070.08018.93
5.4.260.0170.06718.96
5.4.250.0100.07318.84
5.4.240.0100.07018.89
5.4.230.0100.06718.88
5.4.220.0030.08018.93
5.4.210.0070.07319.13
5.4.200.0070.05319.17
5.4.190.0170.06319.02
5.4.180.0100.08018.86
5.4.170.0100.06318.86
5.4.160.0100.07319.02
5.4.150.0100.07719.16
5.4.140.0000.05016.26
5.4.130.0030.06016.41
5.4.120.0170.06016.46
5.4.110.0070.05316.55
5.4.100.0130.07016.52
5.4.90.0100.07016.48
5.4.80.0070.06716.59
5.4.70.0030.06716.52
5.4.60.0070.06316.26
5.4.50.0230.04716.26
5.4.40.0070.07016.46
5.4.30.0100.06716.36
5.4.20.0070.07716.44
5.4.10.0100.06716.42
5.4.00.0030.06715.89
5.3.290.0030.07714.71
5.3.280.0200.05714.55
5.3.270.0100.07314.63
5.3.260.0200.06314.64
5.3.250.0070.08314.68
5.3.240.0100.07314.72
5.3.230.0070.08014.60
5.3.220.0030.06014.51
5.3.210.0170.07014.68
5.3.200.0270.03714.46
5.3.190.0030.04714.66
5.3.180.0070.07314.69
5.3.170.0000.07714.52
5.3.160.0070.07314.66
5.3.150.0070.05314.56
5.3.140.0030.07014.57
5.3.130.0100.06714.62
5.3.120.0130.06714.48
5.3.110.0100.07314.52
5.3.100.0070.07714.15
5.3.90.0130.05714.14
5.3.80.0170.07014.05
5.3.70.0100.07714.06
5.3.60.0030.05013.91
5.3.50.0070.07013.98
5.3.40.0070.04013.88
5.3.30.0200.06013.95
5.3.20.0030.04713.68
5.3.10.0100.03713.78
5.3.00.0100.04713.66
5.2.170.0030.06311.25
5.2.160.0070.06311.18
5.2.150.0170.05011.18
5.2.140.0070.06011.19
5.2.130.0030.06011.11
5.2.120.0030.03310.98
5.2.110.0000.05010.97
5.2.100.0070.06011.10
5.2.90.0030.05311.21
5.2.80.0000.06711.11
5.2.70.0030.03711.01
5.2.60.0030.06711.11
5.2.50.0000.06311.14
5.2.40.0030.05710.87
5.2.30.0030.04711.09
5.2.20.0030.03711.00
5.2.10.0030.06010.80
5.2.00.0000.06310.59
5.1.60.0030.0539.89
5.1.50.0070.03710.07
5.1.40.0100.05010.07
5.1.30.0070.05310.25
5.1.20.0070.03010.45
5.1.10.0070.0539.95
5.1.00.0070.02310.12
5.0.50.0100.0438.93
5.0.40.0030.0438.93
5.0.30.0030.0608.93
5.0.20.0030.0438.93
5.0.10.0000.0278.93
5.0.00.0000.0508.93
4.4.90.0030.0238.93
4.4.80.0030.0338.93
4.4.70.0030.0308.93
4.4.60.0030.0308.93
4.4.50.0030.0308.93
4.4.40.0070.0408.93
4.4.30.0030.0208.93
4.4.20.0000.0338.93
4.4.10.0070.0138.93
4.4.00.0030.0508.93
4.3.110.0000.0378.93
4.3.100.0030.0338.93
4.3.90.0030.0338.93
4.3.80.0070.0478.93
4.3.70.0030.0338.93
4.3.60.0070.0278.93
4.3.50.0100.0308.93
4.3.40.0030.0478.93
4.3.30.0000.0378.93
4.3.20.0000.0378.93
4.3.10.0000.0408.93
4.3.00.0000.0238.93

preferences:
41.27 ms | 400 KiB | 5 Q