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_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.0140.00016.50
8.3.50.0120.00622.87
8.3.40.0090.00918.82
8.3.30.0040.01118.95
8.3.20.0080.00020.29
8.3.10.0030.00523.65
8.3.00.0040.00419.38
8.2.180.0160.00316.75
8.2.170.0120.00322.96
8.2.160.0070.00720.57
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0050.00320.96
8.2.110.0040.00420.34
8.2.100.0060.00618.09
8.2.90.0030.00519.35
8.2.80.0050.00317.97
8.2.70.0030.00617.50
8.2.60.0030.00517.91
8.2.50.0000.01118.07
8.2.40.0050.00318.16
8.2.30.0040.00418.05
8.2.20.0040.00417.64
8.2.10.0040.00418.00
8.2.00.0040.00417.66
8.1.280.0110.00425.92
8.1.270.0060.00323.96
8.1.260.0070.00026.35
8.1.250.0070.00028.09
8.1.240.0080.00322.02
8.1.230.0050.00519.18
8.1.220.0040.00417.74
8.1.210.0060.00318.77
8.1.200.0030.01017.13
8.1.190.0040.00417.25
8.1.180.0080.00018.10
8.1.170.0050.00318.58
8.1.160.0080.00022.05
8.1.150.0000.00818.81
8.1.140.0040.00417.36
8.1.130.0030.00317.83
8.1.120.0040.00417.54
8.1.110.0000.00717.43
8.1.100.0040.00417.50
8.1.90.0070.00017.37
8.1.80.0040.00417.45
8.1.70.0040.00417.42
8.1.60.0070.00317.61
8.1.50.0000.00917.51
8.1.40.0030.00517.46
8.1.30.0040.00417.51
8.1.20.0040.00417.68
8.1.10.0090.00017.59
8.1.00.0000.00817.47
8.0.300.0040.00418.77
8.0.290.0000.00716.88
8.0.280.0000.00718.44
8.0.270.0070.00017.20
8.0.260.0030.00317.43
8.0.250.0000.00717.01
8.0.240.0020.00516.91
8.0.230.0000.00617.02
8.0.220.0070.00017.00
8.0.210.0000.00716.94
8.0.200.0030.00317.01
8.0.190.0040.00417.00
8.0.180.0040.00417.02
8.0.170.0060.00316.89
8.0.160.0040.00417.02
8.0.150.0080.00016.84
8.0.140.0000.01016.92
8.0.130.0060.00013.33
8.0.120.0000.00816.89
8.0.110.0040.00416.93
8.0.100.0050.00216.96
8.0.90.0000.00716.78
8.0.80.0060.00916.95
8.0.70.0040.00416.84
8.0.60.0070.00017.09
8.0.50.0070.00016.96
8.0.30.0100.00817.24
8.0.20.0110.00717.40
8.0.10.0000.00716.95
8.0.00.0090.00816.58
7.4.330.0050.00015.00
7.4.320.0030.00316.45
7.4.300.0030.00316.61
7.4.290.0000.00716.56
7.4.280.0070.00016.52
7.4.270.0030.00316.62
7.4.260.0040.00416.60
7.4.250.0030.00516.56
7.4.240.0020.00516.47
7.4.230.0030.00316.69
7.4.220.0120.00916.57
7.4.210.0060.01316.60
7.4.200.0030.00516.65
7.4.160.0120.00916.63
7.4.150.0110.00717.40
7.4.140.0110.00617.86
7.4.130.0130.00416.49
7.4.120.0080.00916.44
7.4.110.0130.00316.72
7.4.100.0120.00616.39
7.4.90.0090.00916.49
7.4.80.0130.00919.39
7.4.70.0110.01016.72
7.4.60.0100.00716.31
7.4.50.0030.00616.42
7.4.40.0060.01216.61
7.4.30.0060.01216.57
7.4.00.0110.00514.90
7.3.330.0000.00513.26
7.3.320.0000.00613.34
7.3.310.0000.00816.39
7.3.300.0060.00016.42
7.3.290.0030.01516.42
7.3.280.0100.00716.38
7.3.270.0080.01617.40
7.3.260.0130.00416.59
7.3.250.0080.00916.65
7.3.240.0140.00316.80
7.3.230.0130.00716.55
7.3.210.0130.00816.80
7.3.200.0080.00819.39
7.3.190.0120.00616.45
7.3.180.0110.00616.66
7.3.170.0060.00916.68
7.3.160.0090.00616.48
7.3.120.0170.00314.90
7.3.110.0100.00614.70
7.3.100.0090.00614.62
7.3.90.0080.00615.01
7.3.80.0060.00914.77
7.3.70.0100.00314.94
7.3.60.0060.01214.88
7.3.50.0000.01415.09
7.3.40.0070.01014.82
7.3.30.0040.01114.96
7.3.20.0060.01016.56
7.3.10.0020.01216.61
7.3.00.0050.01116.55
7.2.330.0150.00616.58
7.2.320.0120.00616.68
7.2.310.0030.01516.87
7.2.300.0000.02116.75
7.2.290.0070.01016.63
7.2.250.0030.01314.92
7.2.240.0070.01315.09
7.2.230.0060.00614.83
7.2.220.0030.00615.18
7.2.210.0060.00915.07
7.2.200.0040.00715.12
7.2.190.0030.00714.99
7.2.180.0060.00914.89
7.2.170.0060.00615.23
7.2.130.0030.01016.84
7.2.120.0060.00916.98
7.2.110.0150.00916.89
7.2.100.0000.01116.99
7.2.90.0070.01016.82
7.2.80.0000.01817.03
7.2.70.0040.00817.01
7.2.60.0060.00817.02
7.2.50.0000.01817.06
7.2.40.0140.00016.96
7.2.30.0150.00017.18
7.2.20.0000.01516.62
7.2.10.0030.01417.07
7.2.00.0030.01016.75
7.1.330.0070.00715.81
7.1.320.0060.00615.88
7.1.310.0070.01015.98
7.1.300.0040.00715.84
7.1.290.0070.00715.67
7.1.280.0060.00615.75
7.1.270.0060.00615.65
7.1.260.0100.00715.85
7.1.250.0030.01315.94
7.1.200.0030.01115.79
7.1.70.0030.00617.31
7.1.60.0100.01319.46
7.1.50.0070.01417.17
7.1.00.0000.08022.40
7.0.200.0030.00616.89
7.0.140.0030.07722.08
7.0.60.0030.04719.95
7.0.50.0030.07017.91
7.0.40.0000.06020.24
7.0.30.0300.07720.18
7.0.20.0230.06020.22
7.0.10.0100.08720.12
7.0.00.0170.06720.06
5.6.210.0130.08020.48
5.6.200.0200.07018.29
5.6.190.0130.08320.61
5.6.180.0330.07320.39
5.6.170.0170.04320.55
5.6.160.0130.03320.52
5.6.150.0030.04018.16
5.6.140.0100.07718.18
5.6.130.0030.09018.17
5.6.120.0030.04721.02
5.6.110.0030.09021.00
5.6.100.0100.08320.99
5.6.90.0000.04721.01
5.6.80.0300.06020.38
5.5.350.0300.07020.48
5.5.340.0000.08318.02
5.5.330.0070.08720.37
5.5.320.0270.05320.34
5.5.310.0200.04720.27
5.5.300.0030.07718.07
5.5.290.0130.06018.06
5.5.280.0200.03720.86
5.5.270.0170.07320.79
5.5.260.0100.05320.85
5.5.250.0030.05720.69
5.5.240.0170.08020.37
5.4.450.0130.05319.41
5.4.440.0230.04719.40
5.4.430.0170.03719.49
5.4.420.0130.04719.48
5.4.410.0330.03319.39
5.4.400.0200.03719.09
5.4.390.0430.04319.00
5.4.380.0470.08018.73
5.4.370.0470.03718.42
5.4.360.0270.05018.74
5.4.350.0330.04718.61
5.4.340.0300.04718.74
5.4.320.0050.03912.52
5.4.310.0060.03912.51
5.4.300.0030.04712.51
5.4.290.0080.03612.51
5.4.280.0060.03512.41
5.4.270.0040.03812.41
5.4.260.0050.03912.40
5.4.250.0080.03812.41
5.4.240.0060.03712.41
5.4.230.0070.03612.40
5.4.220.0040.03812.40
5.4.210.0060.03512.40
5.4.200.0080.03512.39
5.4.190.0110.03112.40
5.4.180.0030.03912.39
5.4.170.0030.03912.40
5.4.160.0050.03612.40
5.4.150.0060.03612.39
5.4.140.0100.03312.08
5.4.130.0050.03612.06
5.4.120.0080.03412.03
5.4.110.0050.03612.02
5.4.100.0050.03612.02
5.4.90.0060.03712.02
5.4.80.0040.03812.02
5.4.70.0070.03412.02
5.4.60.0070.03312.01
5.4.50.0050.03612.02
5.4.40.0070.03412.00
5.4.30.0080.03412.00
5.4.20.0060.03512.00
5.4.10.0060.03512.00
5.4.00.0070.03511.49
5.3.290.0090.03612.80
5.3.280.0050.03912.71
5.3.270.0060.03912.72
5.3.260.0090.03612.71
5.3.250.0090.03412.72
5.3.240.0100.03312.72
5.3.230.0040.04012.70
5.3.220.0040.04012.68
5.3.210.0040.04112.68
5.3.200.0070.03612.68
5.3.190.0070.03612.68
5.3.180.0050.03812.67
5.3.170.0090.03412.67
5.3.160.0060.03712.68
5.3.150.0070.03712.67
5.3.140.0060.03612.66
5.3.130.0080.04012.66
5.3.120.0100.03412.66
5.3.110.0060.03812.66
5.3.100.0090.04512.13
5.3.90.0080.04512.11
5.3.80.0100.03312.10
5.3.70.0060.03612.11
5.3.60.0090.03212.09
5.3.50.0110.03112.04
5.3.40.0120.03612.04
5.3.30.0060.03612.00
5.3.20.0030.03811.78
5.3.10.0070.03411.75
5.3.00.0060.03611.73
5.2.170.0080.0289.24
5.2.160.0050.0289.24
5.2.150.0040.0319.24
5.2.140.0070.0279.23
5.2.130.0040.0299.20
5.2.120.0040.0299.20
5.2.110.0040.0309.20
5.2.100.0050.0279.20
5.2.90.0050.0289.20
5.2.80.0050.0299.20
5.2.70.0010.0359.19
5.2.60.0060.0309.15
5.2.50.0010.0339.11
5.2.40.0060.0329.09
5.2.30.0050.0299.07
5.2.20.0050.0289.06
5.2.10.0030.0298.96
5.2.00.0040.0298.83
5.1.60.0070.0228.11
5.1.50.0050.0238.11
5.1.40.0060.0238.08
5.1.30.0080.0278.43
5.1.20.0080.0238.46
5.1.10.0060.0258.18
5.1.00.0030.0268.19
5.0.50.0020.0216.67
5.0.40.0030.0196.52
5.0.30.0030.0316.35
5.0.20.0030.0216.31
5.0.10.0040.0246.29
5.0.00.0050.0296.28
4.4.90.0040.0184.78
4.4.80.0040.0174.76
4.4.70.0020.0164.75
4.4.60.0070.0114.75
4.4.50.0020.0164.77
4.4.40.0040.0274.71
4.4.30.0040.0204.76
4.4.20.0030.0224.84
4.4.10.0050.0134.85
4.4.00.0000.0274.76
4.3.110.0040.0174.67
4.3.100.0010.0184.66
4.3.90.0040.0134.63
4.3.80.0020.0254.58
4.3.70.0050.0124.63
4.3.60.0030.0144.63
4.3.50.0030.0154.63
4.3.40.0030.0234.54
4.3.30.0020.0163.32
4.3.20.0030.0153.31
4.3.10.0030.0143.26
4.3.00.0000.01318.23

preferences:
51.79 ms | 401 KiB | 5 Q