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)+1,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; } var_dump($map); // 遍历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="ooo服务服务员服务啦服务员"; $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.0120.00316.63
8.3.50.0090.01123.00
8.3.40.0060.01018.63
8.3.30.0110.00319.27
8.3.20.0040.00420.16
8.3.10.0040.00423.65
8.3.00.0000.00819.25
8.2.180.0040.01516.63
8.2.170.0130.00322.96
8.2.160.0070.00720.52
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0080.00021.10
8.2.110.0060.00320.52
8.2.100.0000.01117.92
8.2.90.0040.00419.20
8.2.80.0060.00317.97
8.2.70.0040.00417.75
8.2.60.0030.00518.03
8.2.50.0060.00318.07
8.2.40.0000.00817.97
8.2.30.0040.00418.06
8.2.20.0040.00417.77
8.2.10.0040.00418.04
8.2.00.0000.00717.68
8.1.280.0160.00625.92
8.1.270.0040.00423.97
8.1.260.0070.00026.35
8.1.250.0070.00028.09
8.1.240.0060.00322.23
8.1.230.0110.00019.22
8.1.220.0090.00017.75
8.1.210.0060.00318.77
8.1.200.0000.01317.23
8.1.190.0000.00917.11
8.1.180.0050.00318.10
8.1.170.0040.00418.71
8.1.160.0070.00022.07
8.1.150.0000.00718.81
8.1.140.0070.00017.45
8.1.130.0000.00717.76
8.1.120.0000.00717.54
8.1.110.0000.00717.35
8.1.100.0040.00417.38
8.1.90.0070.00017.46
8.1.80.0000.00917.34
8.1.70.0020.00517.45
8.1.60.0040.00417.57
8.1.50.0040.00417.57
8.1.40.0040.00417.64
8.1.30.0000.00817.66
8.1.20.0000.00917.56
8.1.10.0000.00817.47
8.1.00.0000.00917.54
8.0.300.0000.00818.77
8.0.290.0000.00916.75
8.0.280.0050.00218.43
8.0.270.0040.00417.29
8.0.260.0030.00317.21
8.0.250.0070.00017.04
8.0.240.0060.00016.91
8.0.230.0030.00316.92
8.0.220.0070.00017.05
8.0.210.0030.00316.90
8.0.200.0000.00617.00
8.0.190.0040.00417.03
8.0.180.0000.00716.97
8.0.170.0040.00416.93
8.0.160.0080.00016.86
8.0.150.0070.00016.96
8.0.140.0070.00316.98
8.0.130.0090.00013.44
8.0.120.0040.00416.98
8.0.110.0040.00416.80
8.0.100.0040.00416.85
8.0.90.0040.00416.97
8.0.80.0120.00316.88
8.0.70.0040.00417.00
8.0.60.0050.00317.01
8.0.50.0050.00216.94
8.0.30.0060.01417.08
8.0.20.0110.00817.40
8.0.10.0040.00417.10
8.0.00.0140.00416.81
7.4.330.0050.00015.09
7.4.320.0030.00316.61
7.4.300.0030.00316.62
7.4.290.0070.00016.54
7.4.280.0000.00716.65
7.4.270.0070.00016.64
7.4.260.0000.00716.46
7.4.250.0040.00416.38
7.4.240.0040.00416.48
7.4.230.0040.00416.67
7.4.220.0070.01116.47
7.4.210.0100.00316.64
7.4.200.0040.00416.52
7.4.160.0070.01416.54
7.4.150.0070.01217.40
7.4.140.0130.00817.86
7.4.130.0070.00916.46
7.4.120.0110.01016.46
7.4.110.0110.00716.70
7.4.100.0070.01016.64
7.4.90.0090.00916.29
7.4.80.0040.01619.39
7.4.70.0040.01416.51
7.4.60.0090.00916.47
7.4.50.0050.00016.59
7.4.40.0120.00616.52
7.4.30.0050.01116.50
7.4.00.0100.00715.17
7.3.330.0050.00013.26
7.3.320.0000.00513.41
7.3.310.0040.00416.38
7.3.300.0000.00716.44
7.3.290.0030.01616.36
7.3.280.0070.00916.36
7.3.270.0120.00617.40
7.3.260.0100.00716.63
7.3.250.0100.00916.52
7.3.240.0140.00716.37
7.3.230.0100.00716.46
7.3.210.0130.01016.64
7.3.200.0110.00719.39
7.3.190.0110.00616.41
7.3.180.0100.01016.73
7.3.170.0040.01216.43
7.3.160.0060.01016.38
7.2.330.0090.00916.80
7.2.320.0100.00716.43
7.2.310.0060.01216.49
7.2.300.0090.01416.81
7.2.290.0110.01116.72
7.2.00.0110.01119.57
7.1.100.0000.01218.07
7.1.70.0040.00417.32
7.1.60.0070.01719.46
7.1.50.0030.01017.12
7.1.00.0070.07322.40
7.0.200.0040.00416.73
7.0.140.0000.07722.00
7.0.110.0130.07319.90
7.0.100.0030.04320.03
7.0.90.0070.07720.04
7.0.80.0030.03719.86
7.0.70.0000.08020.04
7.0.60.0100.08019.98
7.0.50.0070.03720.00
7.0.40.0100.04319.79
7.0.30.0130.03019.87
7.0.20.0000.09719.77
7.0.10.0070.05019.65
7.0.00.0070.04319.71
5.6.280.0000.07721.13
5.6.260.0070.04320.71
5.6.250.0030.09020.67
5.6.240.0000.04320.55
5.6.230.0030.04320.71
5.6.220.0070.08020.70
5.6.210.0030.03320.63
5.6.200.0000.04320.66
5.6.190.0100.06020.57
5.6.180.0100.07720.69
5.6.170.0100.06020.57
5.6.160.0070.08020.65
5.6.150.0070.08320.59
5.6.140.0100.03720.86
5.6.130.0070.04020.86
5.6.120.0070.04320.56
5.6.110.0030.04020.70
5.6.100.0130.03320.58
5.6.90.0070.04020.69
5.6.80.0000.04720.05
5.6.70.0030.03720.02
5.6.60.0070.05020.24
5.6.50.0070.04720.07
5.6.40.0070.07719.96
5.6.30.0070.07320.01
5.6.20.0030.04019.96
5.6.10.0030.07019.93
5.6.00.0070.04020.00
5.5.380.0070.08017.53
5.5.370.0030.06017.55
5.5.360.0070.03717.52
5.5.350.0030.08317.54
5.5.340.0070.08718.25
5.5.330.0030.07718.08
5.5.320.0100.03317.91
5.5.310.0000.03718.09
5.5.300.0030.06317.91
5.5.290.0100.04718.25
5.5.280.0070.04717.82
5.5.270.0000.04318.05
5.5.260.0070.06718.09
5.5.250.0030.04717.79
5.5.240.0000.04017.44
5.5.230.0070.03017.48
5.5.220.0070.04317.48
5.5.210.0070.06017.31
5.5.200.0000.03717.41
5.5.190.0070.07017.26
5.5.180.0100.04717.31
5.5.160.0000.04717.28
5.5.150.0070.07017.18
5.5.140.0070.04317.25
5.5.130.0000.04017.41
5.5.120.0000.08717.30
5.5.110.0030.03317.60
5.5.100.0070.06717.16
5.5.90.0070.04717.16
5.5.80.0100.04017.48
5.5.70.0030.03717.46
5.5.60.0000.05317.47
5.5.50.0070.03017.07
5.5.40.0000.04017.34
5.5.30.0030.04017.29
5.5.20.0070.05717.17
5.5.10.0070.05017.31
5.5.00.0030.06017.16
5.4.450.0070.05319.33
5.4.440.0070.04019.36
5.4.430.0030.04019.35
5.4.420.0070.04719.63
5.4.410.0130.03719.36
5.4.400.0030.04019.18
5.4.390.0070.08718.98
5.4.380.0000.05719.18
5.4.370.0030.03718.99
5.4.360.0030.04718.99
5.4.350.0000.08019.01
5.4.340.0100.05719.14
5.4.320.0030.07019.34
5.4.310.0100.06318.95
5.4.300.0000.08019.06
5.4.290.0130.07319.00
5.4.280.0030.08019.09
5.4.270.0030.07018.95
5.4.260.0070.08019.24
5.4.250.0000.04019.00
5.4.240.0070.03319.02
5.4.230.0030.03719.00
5.4.220.0070.04719.17
5.4.210.0030.03319.02
5.4.200.0030.04719.16
5.4.190.0000.04319.15
5.4.180.0000.04319.00
5.4.170.0030.07019.22
5.4.160.0100.03319.26
5.4.150.0100.06319.20
5.4.140.0070.06016.35
5.4.130.0070.05716.50
5.4.120.0030.05716.39
5.4.110.0030.05716.66
5.4.100.0070.07316.43
5.4.90.0070.03316.41
5.4.80.0000.07716.45
5.4.70.0130.04316.31
5.4.60.0030.07016.41
5.4.50.0070.07016.42
5.4.40.0030.07716.34
5.4.30.0070.07316.38
5.4.20.0070.04716.54
5.4.10.0100.06016.47
5.4.00.0000.04015.74
5.3.290.0100.07014.82
5.3.280.0070.03314.63
5.3.270.0070.05714.62
5.3.260.0000.07714.62
5.3.250.0070.07714.67
5.3.240.0070.03714.71
5.3.230.0070.04714.74
5.3.220.0170.06714.72
5.3.210.0030.08314.59
5.3.200.0030.04014.58
5.3.190.0070.03714.58
5.3.180.0030.06714.63
5.3.170.0070.06714.54
5.3.160.0170.06314.71
5.3.150.0070.07314.59
5.3.140.0070.07314.53
5.3.130.0070.05314.52
5.3.120.0070.08714.69
5.3.110.0070.08014.70
5.3.100.0030.08014.19
5.3.90.0030.06314.16
5.3.80.0030.04314.13
5.3.70.0030.07314.04
5.3.60.0000.05714.04
5.3.50.0070.07013.97
5.3.40.0070.07013.99
5.3.30.0070.07013.94
5.3.20.0100.07013.71
5.3.10.0070.03713.80
5.3.00.0000.04313.63
5.2.170.0030.06312.00
5.2.160.0070.06712.00
5.2.150.0000.04712.00
5.2.140.0030.06012.00
5.2.130.0030.05312.00
5.2.120.0100.04712.00
5.2.110.0100.05712.00
5.2.100.0030.03012.00
5.2.90.0100.06012.00
5.2.80.0000.06012.00
5.2.70.0100.05012.00
5.2.60.0070.06312.00
5.2.50.0070.06012.00
5.2.40.0030.05012.00
5.2.30.0070.06712.00
5.2.20.0030.04312.00
5.2.10.0000.03712.00
5.2.00.0030.03312.00
5.1.60.0070.02312.00
5.1.50.0030.05312.00
5.1.40.0070.05312.00
5.1.30.0000.03012.00
5.1.20.0130.03712.00
5.1.10.0100.04312.00
5.1.00.0070.05312.00
5.0.50.0030.02312.00
5.0.40.0100.03712.00
5.0.30.0030.06312.00
5.0.20.0070.04012.00
5.0.10.0030.04012.00
5.0.00.0070.05712.00
4.4.90.0000.03012.00
4.4.80.0030.02312.00
4.4.70.0000.02012.00
4.4.60.0030.01712.00
4.4.50.0070.02312.00
4.4.40.0000.05012.00
4.4.30.0030.03712.00
4.4.20.0030.02712.00
4.4.10.0030.01312.00
4.4.00.0030.05312.00
4.3.110.0100.02712.00
4.3.100.0030.01712.00
4.3.90.0030.01712.00
4.3.80.0070.02712.00
4.3.70.0000.02712.00
4.3.60.0000.02312.00
4.3.50.0030.02312.00
4.3.40.0000.05012.00
4.3.30.0000.02712.00
4.3.20.0070.02012.00
4.3.10.0030.03312.00
4.3.00.0000.03012.00

preferences:
51.96 ms | 400 KiB | 5 Q