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="服务服务员"; $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.0130.00318.09
8.3.50.0090.00823.00
8.3.40.0070.01418.54
8.3.30.0030.01219.27
8.3.20.0080.00020.17
8.3.10.0000.00823.64
8.3.00.0080.00019.38
8.2.180.0120.00625.92
8.2.170.0070.00718.96
8.2.160.0100.00722.96
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00820.92
8.2.110.0030.01320.47
8.2.100.0090.00318.22
8.2.90.0060.00319.29
8.2.80.0000.00817.97
8.2.70.0000.00817.63
8.2.60.0060.00317.93
8.2.50.0100.00018.07
8.2.40.0050.00318.20
8.2.30.0030.00618.20
8.2.20.0000.00817.66
8.2.10.0040.00418.07
8.2.00.0070.00017.63
8.1.280.0070.01025.92
8.1.270.0070.01421.86
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0070.00323.75
8.1.230.0110.00019.16
8.1.220.0080.00017.79
8.1.210.0080.00018.77
8.1.200.0040.00417.35
8.1.190.0050.00317.35
8.1.180.0040.00418.10
8.1.170.0040.00418.61
8.1.160.0040.00422.02
8.1.150.0070.00018.90
8.1.140.0000.00717.38
8.1.130.0080.00017.83
8.1.120.0040.00417.39
8.1.110.0040.00417.36
8.1.100.0000.00717.52
8.1.90.0060.00317.39
8.1.80.0070.00017.51
8.1.70.0040.00417.40
8.1.60.0060.00317.61
8.1.50.0040.00417.52
8.1.40.0040.00417.61
8.1.30.0040.00417.59
8.1.20.0040.00417.61
8.1.10.0030.00617.60
8.1.00.0000.00717.41
8.0.300.0050.00318.77
8.0.290.0070.00016.75
8.0.280.0040.00418.51
8.0.270.0070.00016.99
8.0.260.0030.00317.33
8.0.250.0070.00017.05
8.0.240.0040.00417.04
8.0.230.0040.00417.03
8.0.220.0000.00816.86
8.0.210.0000.00716.97
8.0.200.0000.00717.03
8.0.190.0030.00417.04
8.0.180.0000.00716.88
8.0.170.0030.00516.94
8.0.160.0040.00416.95
8.0.150.0030.00316.84
8.0.140.0040.00816.96
8.0.130.0060.00613.43
8.0.120.0050.00316.96
8.0.110.0040.00416.94
8.0.100.0000.00816.84
8.0.90.0000.00716.92
8.0.80.0040.01217.00
8.0.70.0030.00516.85
8.0.60.0050.00317.08
8.0.50.0000.00717.00
8.0.30.0100.01316.96
8.0.20.0110.01117.40
8.0.10.0000.00717.02
8.0.00.0080.01016.79
7.4.330.0000.00515.14
7.4.320.0000.00616.61
7.4.300.0040.00416.64
7.4.290.0030.00316.52
7.4.280.0000.00716.52
7.4.270.0000.00716.66
7.4.260.0070.00016.48
7.4.250.0070.00016.61
7.4.240.0050.00316.53
7.4.230.0070.00016.35
7.4.220.0100.00716.48
7.4.210.0140.00016.57
7.4.200.0080.00016.43
7.4.160.0090.00916.42
7.4.150.0150.00317.40
7.4.140.0100.00717.86
7.4.130.0090.01116.53
7.4.120.0140.00516.53
7.4.110.0100.00716.51
7.4.100.0140.00416.50
7.4.90.0070.01116.42
7.4.80.0110.00719.39
7.4.70.0070.01016.46
7.4.60.0170.00416.50
7.4.50.0060.00316.56
7.4.40.0000.01716.55
7.4.30.0090.00816.38
7.4.00.0030.01315.18
7.3.330.0000.00613.30
7.3.320.0030.00313.31
7.3.310.0040.00416.29
7.3.300.0030.00316.25
7.3.290.0030.01316.32
7.3.280.0060.00916.40
7.3.270.0110.00817.40
7.3.260.0040.01316.46
7.3.250.0100.01116.41
7.3.240.0160.00316.61
7.3.230.0080.00816.59
7.3.210.0130.00716.58
7.3.200.0060.01519.39
7.3.190.0060.01316.66
7.3.180.0090.01116.46
7.3.170.0120.00916.54
7.3.160.0080.00816.41
7.2.330.0090.00916.70
7.2.320.0110.00716.88
7.2.310.0080.01216.80
7.2.300.0120.00816.84
7.2.290.0080.00816.81
7.2.60.0030.01016.86
7.2.00.0110.00718.95
7.1.200.0000.01315.93
7.1.100.0070.00418.15
7.1.70.0000.00717.18
7.1.60.0140.01119.46
7.1.50.0080.00417.20
7.1.00.0000.08022.44
7.0.200.0030.00516.73
7.0.140.0000.07722.18
7.0.60.0030.04320.05
7.0.50.0030.06317.91
7.0.40.0030.04320.11
7.0.30.0430.06320.07
7.0.20.0270.04320.16
7.0.10.0170.07320.30
7.0.00.0100.07320.29
5.6.210.0070.08020.58
5.6.200.0030.08718.29
5.6.190.0070.05020.66
5.6.180.0370.03720.55
5.6.170.0200.04020.51
5.6.160.0070.08020.61
5.6.150.0070.08018.29
5.6.140.0070.03318.21
5.6.130.0070.07718.28
5.6.120.0100.04320.99
5.6.110.0070.08320.99
5.6.100.0030.04021.02
5.6.90.0100.05020.95
5.6.80.0100.06320.40
5.5.350.0300.07020.46
5.5.340.0000.04318.06
5.5.330.0030.05020.19
5.5.320.0400.07020.25
5.5.310.0430.07020.31
5.5.300.0070.07317.98
5.5.290.0030.05017.97
5.5.280.0030.06320.86
5.5.270.0030.08720.74
5.5.260.0100.07720.98
5.5.250.0070.03720.80
5.5.240.0000.03320.25
5.4.450.0300.04319.37
5.4.440.0230.04019.64
5.4.430.0170.04019.57
5.4.420.0470.04319.19
5.4.410.0430.03719.09
5.4.400.0470.04719.07
5.4.390.0130.06319.03
5.4.380.0270.05718.57
5.4.370.0430.06018.58
5.4.360.0470.04718.83
5.4.350.0630.04318.71
5.4.340.0470.05018.54
5.4.320.0070.03612.51
5.4.310.0060.04112.51
5.4.300.0050.03912.51
5.4.290.0120.03112.51
5.4.280.0040.03712.41
5.4.270.0070.03512.41
5.4.260.0060.04012.41
5.4.250.0060.03812.41
5.4.240.0070.03512.41
5.4.230.0070.03612.40
5.4.220.0100.03212.40
5.4.210.0060.03712.40
5.4.200.0100.04812.40
5.4.190.0060.03612.39
5.4.180.0040.03912.40
5.4.170.0070.03612.40
5.4.160.0050.03712.39
5.4.150.0070.03512.39
5.4.140.0070.03612.08
5.4.130.0090.03312.06
5.4.120.0060.03512.03
5.4.110.0030.03912.02
5.4.100.0080.03512.02
5.4.90.0080.03612.02
5.4.80.0080.03512.02
5.4.70.0040.03712.02
5.4.60.0070.03412.02
5.4.50.0070.03412.01
5.4.40.0060.04512.01
5.4.30.0050.04312.00
5.4.20.0060.03512.00
5.4.10.0080.03312.00
5.4.00.0100.03211.49
5.3.290.0090.03712.80
5.3.280.0050.03812.71
5.3.270.0100.04312.72
5.3.260.0070.04212.72
5.3.250.0060.03912.72
5.3.240.0070.03712.72
5.3.230.0090.03512.71
5.3.220.0060.03812.68
5.3.210.0050.04012.68
5.3.200.0090.03312.68
5.3.190.0070.03712.67
5.3.180.0070.03612.67
5.3.170.0070.03512.67
5.3.160.0070.03612.67
5.3.150.0080.03512.67
5.3.140.0030.04012.66
5.3.130.0100.03512.66
5.3.120.0080.04412.66
5.3.110.0120.03512.66
5.3.100.0050.03912.13
5.3.90.0100.03212.12
5.3.80.0040.03812.10
5.3.70.0050.03712.10
5.3.60.0050.03712.09
5.3.50.0070.03512.04
5.3.40.0060.03712.04
5.3.30.0030.03712.00
5.3.20.0090.03111.78
5.3.10.0060.03511.74
5.3.00.0060.03511.73
5.2.170.0040.0319.24
5.2.160.0060.0289.24
5.2.150.0050.0299.24
5.2.140.0050.0299.24
5.2.130.0060.0279.20
5.2.120.0070.0269.20
5.2.110.0010.0339.20
5.2.100.0030.0309.20
5.2.90.0040.0309.20
5.2.80.0060.0299.20
5.2.70.0050.0309.19
5.2.60.0040.0309.15
5.2.50.0040.0349.12
5.2.40.0060.0279.09
5.2.30.0010.0339.07
5.2.20.0040.0299.05
5.2.10.0110.0218.96
5.2.00.0080.0268.83
5.1.60.0020.0268.11
5.1.50.0020.0268.11
5.1.40.0070.0218.08
5.1.30.0080.0228.43
5.1.20.0050.0278.46
5.1.10.0020.0298.19
5.1.00.0020.0288.19
5.0.50.0050.0206.66
5.0.40.0020.0216.53
5.0.30.0040.0326.34
5.0.20.0020.0226.31
5.0.10.0050.0196.28
5.0.00.0040.0306.28
4.4.90.0040.0154.78
4.4.80.0030.0144.75
4.4.70.0020.0164.76
4.4.60.0040.0154.76
4.4.50.0040.0144.77
4.4.40.0050.0234.71
4.4.30.0040.0214.76
4.4.20.0040.0194.85
4.4.10.0030.0154.85
4.4.00.0060.0224.76
4.3.110.0040.0144.67
4.3.100.0030.0154.66
4.3.90.0030.0174.63
4.3.80.0010.0274.59
4.3.70.0030.0144.63
4.3.60.0040.0214.63
4.3.50.0020.0194.63
4.3.40.0030.0244.54
4.3.30.0010.0173.32
4.3.20.0030.0213.30
4.3.10.0000.0183.26
4.3.00.0070.01718.23

preferences:
56.1 ms | 401 KiB | 5 Q