3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setKeyWords($str,$word_arr=array()){ // 设置多字节字符内部编码为utf8 mb_internal_encoding("UTF-8"); // 创建一个跟字符串长度一致的数组,用0填充 $map=array_fill(0,mb_strlen($str),0); // 遍历关键词数组,将关键词对应的map数组的位置上的数字置为1 foreach ($word_arr as $value) { $pos=-1; $pos_count=0; $pos_arr=array(); // 如果找到了这个关键词,就将这个词的位置存入位置数组中(来支持多次出现此关键词的情况) while(($pos=mb_strpos($str,$value,$pos+1))!==false && $pos_count<5){ $pos_arr[]=$pos; $pos_count++; } // 遍历数组,将对应位置置1 foreach ($pos_arr as $pos_val) { if($pos_val!==false){ $fill=array_fill($pos_val,mb_strlen($value),1); $map = array_replace($map,$fill); } } $pos=null; } // 遍历map数组,加入高亮代码 $flag=0; $position=-1; $result=""; // 结果数组 foreach ($map as $key => $value) { if($value==1){ // 如果第一次出现1,则加上html标签头 if($flag==0) $result.="<span class=\"fc-red\">"; $flag=1; }else{ // 如果已经到了一个0,但上一个还是1时,加入html标签尾 if($flag==1){ $position=$key-1; $flag=0; $result.="</span>"; } } // 将该位置的字符加入结果字符串中 $result.=mb_substr($str,$key,1); } return $result; } $title="服务服务员服务员服务服务服务员"; $arr=array("服务员","服务"); echo setKeyWords($title,$arr);

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.0070.00716.63
8.3.50.0060.01219.81
8.3.40.0150.00318.85
8.3.30.0030.01018.82
8.3.20.0050.00320.34
8.3.10.0080.00023.61
8.3.00.0050.00319.25
8.2.180.0110.00416.50
8.2.170.0110.00322.96
8.2.160.0110.00420.58
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0050.00221.04
8.2.110.0040.00420.40
8.2.100.0040.00718.22
8.2.90.0040.00419.31
8.2.80.0040.00417.97
8.2.70.0090.00317.50
8.2.60.0000.00817.93
8.2.50.0030.00618.07
8.2.40.0040.00418.34
8.2.30.0000.00718.09
8.2.20.0040.00417.80
8.2.10.0000.00817.94
8.2.00.0020.00517.86
8.1.270.0050.00323.76
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0100.00023.71
8.1.230.0080.00419.04
8.1.220.0000.00917.76
8.1.210.0060.00318.77
8.1.200.0100.00317.10
8.1.190.0000.00817.23
8.1.180.0050.00318.10
8.1.170.0060.00318.63
8.1.160.0020.00522.02
8.1.150.0060.00318.82
8.1.140.0040.00417.36
8.1.130.0070.00017.37
8.1.120.0040.00417.51
8.1.110.0000.00817.52
8.1.100.0040.00417.36
8.1.90.0050.00217.36
8.1.80.0030.00717.46
8.1.70.0000.00817.42
8.1.60.0000.00917.65
8.1.50.0060.00317.64
8.1.40.0000.00717.62
8.1.30.0030.00617.51
8.1.20.0050.00317.71
8.1.10.0040.00417.60
8.1.00.0040.00417.48
8.0.300.0030.00518.77
8.0.290.0040.00416.88
8.0.280.0040.00418.50
8.0.270.0040.00416.87
8.0.260.0070.00016.88
8.0.250.0070.00016.96
8.0.240.0000.00716.91
8.0.230.0000.00717.01
8.0.220.0040.00316.98
8.0.210.0080.00017.02
8.0.200.0000.00716.90
8.0.190.0040.00417.03
8.0.180.0000.00716.96
8.0.170.0060.00317.04
8.0.160.0000.00716.96
8.0.150.0000.00816.79
8.0.140.0060.00616.91
8.0.130.0030.00313.43
8.0.120.0040.00416.91
8.0.110.0000.00816.91
8.0.100.0070.00016.84
8.0.90.0040.00417.07
8.0.80.0170.00316.91
8.0.70.0050.00216.96
8.0.60.0050.00316.94
8.0.50.0070.00017.01
8.0.30.0100.01117.01
8.0.20.0080.01217.40
8.0.10.0040.00416.89
8.0.00.0110.00516.71
7.4.330.0020.00215.13
7.4.320.0060.00016.53
7.4.300.0070.00016.44
7.4.290.0030.00316.65
7.4.280.0080.00016.64
7.4.270.0000.00816.54
7.4.260.0070.00016.46
7.4.250.0040.00416.47
7.4.240.0020.00516.51
7.4.230.0070.00016.60
7.4.220.0100.01016.56
7.4.210.0030.01616.64
7.4.200.0000.00716.60
7.4.160.0000.01516.23
7.4.150.0110.00717.40
7.4.140.0120.01217.86
7.4.130.0110.00516.46
7.4.120.0080.01016.61
7.4.110.0090.00916.54
7.4.100.0140.00716.51
7.4.90.0070.01116.63
7.4.80.0070.01619.39
7.4.70.0120.01216.63
7.4.60.0070.01016.43
7.4.50.0050.00416.48
7.4.40.0030.01216.66
7.4.30.0070.01016.61
7.4.10.0110.00815.03
7.4.00.0050.01214.92
7.3.330.0000.00513.23
7.3.320.0060.00013.26
7.3.310.0000.00716.44
7.3.300.0000.00716.23
7.3.290.0120.00916.43
7.3.280.0040.01216.34
7.3.270.0130.00717.40
7.3.260.0070.01416.52
7.3.250.0110.00616.50
7.3.240.0060.01216.59
7.3.230.0060.00916.67
7.3.210.0140.00716.59
7.3.200.0090.01219.39
7.3.190.0070.01016.35
7.3.180.0140.00316.48
7.3.170.0070.01116.32
7.3.160.0090.01016.73
7.3.130.0050.01314.93
7.3.120.0040.01214.95
7.3.110.0050.01314.90
7.3.100.0050.01014.99
7.3.90.0090.00614.89
7.3.80.0050.00614.92
7.3.70.0020.01015.02
7.3.60.0070.00714.84
7.3.50.0100.00614.85
7.3.40.0030.01014.86
7.3.30.0100.00414.86
7.3.20.0070.00816.54
7.3.10.0110.00716.67
7.3.00.0080.00716.60
7.2.330.0120.01116.87
7.2.320.0080.00816.67
7.2.310.0150.00616.88
7.2.300.0100.01016.86
7.2.290.0060.01116.86
7.2.260.0070.01215.26
7.2.250.0070.01115.08
7.2.240.0090.00614.98
7.2.230.0070.00715.25
7.2.220.0020.01214.93
7.2.210.0060.00715.17
7.2.200.0030.00915.13
7.2.190.0060.01115.00
7.2.180.0050.01115.01
7.2.170.0020.01215.17
7.2.160.0020.01315.11
7.2.150.0070.01016.92
7.2.140.0060.01016.97
7.2.130.0070.00816.88
7.2.120.0070.00916.80
7.2.110.0050.01016.92
7.2.100.0050.01216.83
7.2.90.0070.01016.88
7.2.80.0070.01016.90
7.2.70.0100.00716.89
7.2.60.0100.00516.84
7.2.50.0090.00716.88
7.2.40.0080.00716.96
7.2.30.0080.00816.82
7.2.20.0070.01016.83
7.2.10.0080.00916.89
7.2.00.0110.00817.40
7.1.330.0020.01015.80
7.1.320.0040.01015.73
7.1.310.0060.00615.80
7.1.300.0050.00915.82
7.1.290.0080.00715.63
7.1.280.0080.00515.88
7.1.270.0050.00815.79
7.1.260.0090.00615.77
7.1.250.0090.00515.80
7.1.240.0070.00315.68
7.1.230.0020.01115.72
7.1.220.0050.00815.75
7.1.210.0050.01015.70
7.1.200.0080.00415.80
7.1.190.0060.00915.91
7.1.180.0060.00915.72
7.1.170.0020.01315.72
7.1.160.0070.00415.74
7.1.150.0030.00815.79
7.1.140.0050.00815.84
7.1.130.0070.00715.93
7.1.120.0030.01015.86
7.1.110.0060.00615.93
7.1.100.0070.00616.49
7.1.90.0040.00915.79
7.1.80.0080.00615.80
7.1.70.0040.00716.39
7.1.60.0070.00916.98
7.1.50.0040.01116.31
7.1.40.0020.00915.59
7.1.30.0070.00315.87
7.1.20.0050.00615.80
7.1.10.0080.00715.86
7.1.00.0050.02918.05
7.0.330.0080.00615.28
7.0.320.0060.00615.24
7.0.310.0020.01215.31
7.0.300.0070.00515.48
7.0.290.0050.00915.48
7.0.280.0070.00415.25
7.0.270.0040.00515.37
7.0.260.0030.01015.26
7.0.250.0060.00615.40
7.0.240.0100.00315.33
7.0.230.0020.01015.43
7.0.220.0040.00915.50
7.0.210.0080.00415.48
7.0.200.0010.01015.94
7.0.190.0000.01015.51
7.0.180.0050.00815.44
7.0.170.0050.00815.54
7.0.160.0090.00315.47
7.0.150.0040.00715.54
7.0.140.0060.02817.64
7.0.130.0070.00715.50
7.0.120.0090.00315.55
7.0.110.0050.00615.50
7.0.100.0030.00715.32
7.0.90.0030.00815.37
7.0.80.0050.00815.52
7.0.70.0040.00915.46
7.0.60.0020.01916.93
7.0.50.0050.02416.12
7.0.40.0050.01915.65
7.0.30.0120.02015.79
7.0.20.0120.03215.78
7.0.10.0050.03415.71
7.0.00.0080.03315.63
5.6.400.0070.00914.45
5.6.390.0100.00514.66
5.6.380.0030.01014.47
5.6.370.0060.00714.65
5.6.360.0020.00814.22
5.6.350.0050.00714.25
5.6.340.0070.00614.36
5.6.330.0030.00714.58
5.6.320.0010.01114.59
5.6.310.0060.00614.63
5.6.300.0070.00714.56
5.6.290.0020.00714.42
5.6.280.0060.02816.60
5.6.270.0060.00714.72
5.6.260.0040.00714.50
5.6.250.0030.00814.22
5.6.240.0070.01014.45
5.6.230.0050.01014.42
5.6.220.0080.00514.30
5.6.210.0090.02816.56
5.6.200.0090.03115.69
5.6.190.0100.02516.42
5.6.180.0150.02316.41
5.6.170.0110.02316.36
5.6.160.0010.02416.33
5.6.150.0060.01815.64
5.6.140.0100.03215.72
5.6.130.0060.02415.67
5.6.120.0080.01716.55
5.6.110.0100.03016.70
5.6.100.0070.02716.64
5.6.90.0080.03116.57
5.6.80.0060.03316.44
5.6.70.0070.00614.34
5.6.60.0030.01114.25
5.6.50.0080.00314.51
5.6.40.0050.00814.24
5.6.30.0070.00414.49
5.6.20.0030.00914.24
5.6.10.0080.00214.43
5.6.00.0080.00514.36
5.5.380.0060.00314.30
5.5.370.0040.01114.47
5.5.360.0000.01114.42
5.5.350.0130.02916.33
5.5.340.0070.03215.54
5.5.330.0050.03116.31
5.5.320.0170.02316.46
5.5.310.0130.01916.42
5.5.300.0060.03215.61
5.5.290.0030.02215.52
5.5.280.0070.02916.35
5.5.270.0060.02816.64
5.5.260.0050.01916.52
5.5.250.0080.01816.44
5.5.240.0120.02816.37
5.5.230.0110.00514.28
5.5.220.0020.01214.42
5.5.210.0080.00514.36
5.5.200.0040.00814.22
5.5.190.0060.00914.40
5.5.180.0070.00514.35
5.5.170.0080.00814.39
5.5.160.0070.00514.32
5.5.150.0070.00414.21
5.5.140.0060.00714.26
5.5.130.0070.00914.37
5.5.120.0100.00314.31
5.5.110.0070.00614.20
5.5.100.0060.00814.22
5.5.90.0040.00714.48
5.5.80.0050.00714.15
5.5.70.0090.00014.33
5.5.60.0040.00814.09
5.5.50.0070.00614.38
5.5.40.0060.01014.26
5.5.30.0060.00614.13
5.5.20.0050.01014.29
5.5.10.0050.00714.24
5.5.00.0060.00614.18
5.4.450.0130.01814.74
5.4.440.0230.01514.65
5.4.430.0080.02114.65
5.4.420.0290.00914.79
5.4.410.0100.02214.74
5.4.400.0120.01514.65
5.4.390.0090.01614.67
5.4.380.0140.02414.52
5.4.370.0130.02214.44
5.4.360.0120.02414.53
5.4.350.0190.02014.51
5.4.340.0200.02514.52
5.4.330.0030.00812.40
5.4.320.0060.01812.44
5.4.310.0060.01612.44
5.4.300.0050.01612.44
5.4.290.0070.01512.44
5.4.280.0040.01612.40
5.4.270.0040.01812.40
5.4.260.0060.02012.40
5.4.250.0060.01612.40
5.4.240.0050.01612.40
5.4.230.0050.01712.40
5.4.220.0030.02012.40
5.4.210.0050.01612.40
5.4.200.0030.01812.40
5.4.190.0060.01412.40
5.4.180.0080.01812.40
5.4.170.0070.01912.40
5.4.160.0050.01612.40
5.4.150.0070.01512.40
5.4.140.0050.01512.29
5.4.130.0060.01412.29
5.4.120.0030.01712.27
5.4.110.0040.01612.27
5.4.100.0060.01512.27
5.4.90.0030.01712.27
5.4.80.0030.01812.27
5.4.70.0050.01612.27
5.4.60.0020.01812.27
5.4.50.0040.01412.27
5.4.40.0030.01612.27
5.4.30.0080.01212.27
5.4.20.0050.01512.27
5.4.10.0030.01712.27
5.4.00.0050.01512.10
5.3.290.0040.04112.80
5.3.280.0090.03512.71
5.3.270.0060.04012.73
5.3.260.0070.03812.72
5.3.250.0120.04112.72
5.3.240.0060.03612.72
5.3.230.0060.03712.71
5.3.220.0040.04112.68
5.3.210.0080.03712.68
5.3.200.0090.03512.68
5.3.190.0130.04012.68
5.3.180.0100.03412.67
5.3.170.0060.03812.67
5.3.160.0060.03712.67
5.3.150.0070.03612.68
5.3.140.0070.03512.66
5.3.130.0060.04012.66
5.3.120.0100.03512.66
5.3.110.0060.03912.66
5.3.100.0040.03912.13
5.3.90.0080.03612.12
5.3.80.0040.03912.10
5.3.70.0050.03812.10
5.3.60.0080.03512.09
5.3.50.0060.03612.04
5.3.40.0060.03712.04
5.3.30.0080.03312.00
5.3.20.0050.03711.78
5.3.10.0060.03511.74
5.3.00.0060.03611.73
5.2.170.0030.0329.24
5.2.160.0050.0299.24
5.2.150.0100.0259.24
5.2.140.0070.0369.24
5.2.130.0070.0279.20
5.2.120.0040.0299.20
5.2.110.0070.0379.21
5.2.100.0050.0309.20
5.2.90.0070.0279.20
5.2.80.0070.0289.19
5.2.70.0080.0279.19
5.2.60.0090.0259.15
5.2.50.0050.0329.12
5.2.40.0110.0309.10
5.2.30.0040.0319.07
5.2.20.0040.0309.06
5.2.10.0070.0268.96
5.2.00.0050.0288.82
5.1.60.0050.0238.11
5.1.50.0040.0258.11
5.1.40.0040.0258.09
5.1.30.0070.0238.44
5.1.20.0050.0308.46
5.1.10.0040.0278.18
5.1.00.0030.0278.18
5.0.50.0040.0206.66
5.0.40.0040.0186.53
5.0.30.0030.0316.34
5.0.20.0040.0196.30
5.0.10.0030.0206.29
5.0.00.0010.0346.27
4.4.90.0040.0214.78
4.4.80.0020.0174.75
4.4.70.0030.0154.75
4.4.60.0010.0184.75
4.4.50.0030.0154.77
4.4.40.0030.0254.71
4.4.30.0030.0174.76
4.4.20.0020.0184.85
4.4.10.0010.0174.85
4.4.00.0010.0314.76
4.3.110.0050.0134.67
4.3.100.0050.0124.66
4.3.90.0050.0124.63
4.3.80.0020.0244.58
4.3.70.0010.0164.63
4.3.60.0040.0144.63
4.3.50.0050.0144.62
4.3.40.0020.0244.54
4.3.30.0030.0153.33
4.3.20.0020.0163.30
4.3.10.0040.0143.26
4.3.00.0000.02018.23

preferences:
59.2 ms | 400 KiB | 5 Q