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.0030.01418.43
8.3.50.0070.01322.93
8.3.40.0150.00318.97
8.3.30.0030.01019.17
8.3.20.0040.00420.16
8.3.10.0050.00323.66
8.3.00.0090.00019.38
8.2.180.0160.00616.38
8.2.170.0070.00722.96
8.2.160.0100.00320.39
8.2.150.0050.00324.18
8.2.140.0030.00624.66
8.2.130.0080.00026.16
8.2.120.0040.00420.79
8.2.110.0070.00420.53
8.2.100.0070.00418.34
8.2.90.0050.00319.17
8.2.80.0040.00417.97
8.2.70.0040.00417.38
8.2.60.0040.00417.93
8.2.50.0030.00718.07
8.2.40.0030.00518.16
8.2.30.0050.00318.19
8.2.20.0000.00717.80
8.2.10.0000.00718.04
8.2.00.0060.00317.75
8.1.280.0060.01225.92
8.1.270.0000.00823.61
8.1.260.0030.00326.35
8.1.250.0070.00028.09
8.1.240.0060.00320.98
8.1.230.0070.00419.01
8.1.220.0060.00317.74
8.1.210.0030.00518.77
8.1.200.0060.00617.23
8.1.190.0050.00317.13
8.1.180.0080.00018.10
8.1.170.0040.00418.58
8.1.160.0020.00522.00
8.1.150.0030.00518.83
8.1.140.0070.00017.45
8.1.130.0070.00017.74
8.1.120.0070.00017.31
8.1.110.0050.00217.42
8.1.100.0030.00317.46
8.1.90.0040.00417.46
8.1.80.0000.01017.44
8.1.70.0040.00417.37
8.1.60.0060.00317.65
8.1.50.0060.00317.58
8.1.40.0000.00717.45
8.1.30.0050.00317.57
8.1.20.0030.00517.74
8.1.10.0000.00917.60
8.1.00.0040.00417.52
8.0.300.0000.00718.77
8.0.290.0040.00416.75
8.0.280.0000.00718.50
8.0.270.0000.00717.27
8.0.260.0030.00317.21
8.0.250.0000.00716.90
8.0.240.0070.00016.91
8.0.230.0070.00016.99
8.0.220.0000.00817.00
8.0.210.0070.00016.93
8.0.200.0070.00016.91
8.0.190.0070.00017.02
8.0.180.0070.00016.88
8.0.170.0080.00017.03
8.0.160.0070.00016.94
8.0.150.0000.00716.97
8.0.140.0030.00616.91
8.0.130.0080.00013.32
8.0.120.0070.00016.95
8.0.110.0000.00816.86
8.0.100.0040.00416.99
8.0.90.0040.00416.90
8.0.80.0090.00616.84
8.0.70.0050.00216.79
8.0.60.0080.00017.02
8.0.50.0040.00416.90
8.0.30.0160.00317.05
8.0.20.0130.00617.40
8.0.10.0040.00416.87
8.0.00.0090.00916.69
7.4.330.0060.00015.10
7.4.320.0060.00016.66
7.4.300.0000.00616.62
7.4.290.0040.00416.43
7.4.280.0000.00816.60
7.4.270.0070.00016.62
7.4.260.0000.00716.48
7.4.250.0000.00816.34
7.4.240.0020.00616.49
7.4.230.0070.00016.27
7.4.220.0070.01116.44
7.4.210.0030.01016.69
7.4.200.0030.00316.67
7.4.160.0100.01016.71
7.4.150.0150.00317.40
7.4.140.0080.01217.86
7.4.130.0080.01016.50
7.4.120.0090.00816.59
7.4.110.0100.00716.39
7.4.100.0040.01416.59
7.4.90.0030.01416.41
7.4.80.0090.00919.39
7.4.70.0100.00716.52
7.4.60.0120.01216.40
7.4.50.0090.00016.47
7.4.40.0030.01416.55
7.4.30.0080.00816.60
7.4.00.0070.01114.72
7.3.330.0000.00513.38
7.3.320.0030.00313.26
7.3.310.0070.00016.26
7.3.300.0030.00316.45
7.3.290.0090.00616.39
7.3.280.0080.00616.38
7.3.270.0000.01717.40
7.3.260.0130.00416.68
7.3.250.0070.01016.40
7.3.240.0100.00716.66
7.3.230.0070.01016.42
7.3.210.0060.01116.47
7.3.200.0130.01019.39
7.3.190.0110.00716.80
7.3.180.0080.00816.80
7.3.170.0120.00316.77
7.3.160.0090.00916.65
7.3.10.0170.00316.33
7.3.00.0090.00916.45
7.2.330.0090.01216.82
7.2.320.0080.01116.54
7.2.310.0120.00616.89
7.2.300.0140.00916.50
7.2.290.0000.01716.68
7.2.130.0060.01216.41
7.2.120.0020.00916.55
7.2.110.0030.01116.50
7.2.100.0070.01416.63
7.2.90.0190.00316.27
7.2.80.0060.01216.17
7.2.70.0070.01116.66
7.2.60.0110.00316.59
7.2.50.0030.00816.76
7.2.40.0130.00016.47
7.2.30.0100.00316.55
7.2.20.0190.00416.54
7.2.10.0080.00416.68
7.2.00.0070.00316.90
7.1.250.0140.00615.39
7.1.70.0040.00717.23
7.1.60.0130.00619.46
7.1.50.0100.00717.04
7.1.00.0100.07022.36
7.0.200.0000.00916.88
7.0.140.0070.07022.06
7.0.60.0030.05320.00
7.0.50.0130.07318.00
7.0.40.0070.04020.27
7.0.30.0300.08020.27
7.0.20.0230.05020.12
7.0.10.0000.08020.09
7.0.00.0030.05720.23
5.6.280.0000.07721.08
5.6.210.0100.07020.72
5.6.200.0070.07718.16
5.6.190.0030.08320.27
5.6.180.0330.08020.64
5.6.170.0130.04720.62
5.6.160.0070.05020.46
5.6.150.0100.07718.19
5.6.140.0030.05018.12
5.6.130.0070.05018.28
5.6.120.0100.08721.02
5.6.110.0100.08321.12
5.6.100.0070.05020.97
5.6.90.0130.08021.01
5.6.80.0030.05720.44
5.5.350.0270.07320.50
5.5.340.0000.04317.98
5.5.330.0000.07020.19
5.5.320.0400.05020.34
5.5.310.0470.06720.38
5.5.300.0000.05317.94
5.5.290.0000.06018.01
5.5.280.0070.08020.79
5.5.270.0100.08320.80
5.5.260.0130.06320.90
5.5.250.0200.08320.50
5.5.240.0030.08720.27
5.4.450.0430.04719.17
5.4.440.0170.02719.16
5.4.430.0330.04719.54
5.4.420.0370.04019.52
5.4.410.0200.04719.11
5.4.400.0100.04719.00
5.4.390.0270.03318.98
5.4.380.0230.06318.77
5.4.370.0330.05718.62
5.4.360.0330.05018.54
5.4.350.0370.04318.80
5.4.340.0400.05318.77
5.4.320.0040.03712.51
5.4.310.0060.03812.51
5.4.300.0090.03512.51
5.4.290.0040.04012.51
5.4.280.0050.03612.41
5.4.270.0060.03712.41
5.4.260.0050.03912.41
5.4.250.0050.03912.41
5.4.240.0070.03512.41
5.4.230.0060.03712.40
5.4.220.0060.03612.40
5.4.210.0050.03612.40
5.4.200.0070.03712.40
5.4.190.0070.03412.39
5.4.180.0040.03712.39
5.4.170.0040.03812.41
5.4.160.0030.03812.40
5.4.150.0090.03712.39
5.4.140.0040.03912.08
5.4.130.0070.03512.07
5.4.120.0070.03412.02
5.4.110.0070.03412.02
5.4.100.0050.03612.02
5.4.90.0040.03912.02
5.4.80.0060.03912.02
5.4.70.0070.03412.02
5.4.60.0030.03712.02
5.4.50.0070.03412.02
5.4.40.0030.03612.00
5.4.30.0060.03512.00
5.4.20.0080.03212.00
5.4.10.0090.03012.00
5.4.00.0090.03211.49
5.3.290.0090.03712.80
5.3.280.0100.03412.70
5.3.270.0080.03712.72
5.3.260.0030.04212.72
5.3.250.0060.03712.72
5.3.240.0060.03712.72
5.3.230.0070.03612.71
5.3.220.0070.03512.68
5.3.210.0070.03812.68
5.3.200.0050.03712.68
5.3.190.0100.03312.68
5.3.180.0040.03712.67
5.3.170.0020.04012.67
5.3.160.0050.03712.67
5.3.150.0070.03512.68
5.3.140.0060.03612.66
5.3.130.0060.03812.66
5.3.120.0050.03912.66
5.3.110.0100.03512.66
5.3.100.0050.03712.13
5.3.90.0060.03512.11
5.3.80.0070.03412.11
5.3.70.0070.03412.10
5.3.60.0080.03412.09
5.3.50.0100.03212.04
5.3.40.0060.03612.04
5.3.30.0020.03812.00
5.3.20.0080.03211.78
5.3.10.0040.03511.75
5.3.00.0060.04411.73
5.2.170.0060.0319.24
5.2.160.0050.0339.24
5.2.150.0030.0329.24
5.2.140.0040.0339.23
5.2.130.0020.0329.20
5.2.120.0020.0319.20
5.2.110.0050.0299.20
5.2.100.0030.0319.20
5.2.90.0070.0279.20
5.2.80.0050.0319.20
5.2.70.0040.0319.19
5.2.60.0050.0299.15
5.2.50.0050.0299.12
5.2.40.0050.0289.09
5.2.30.0040.0309.07
5.2.20.0030.0299.05
5.2.10.0020.0308.96
5.2.00.0050.0288.82
5.1.60.0060.0218.11
5.1.50.0030.0258.11
5.1.40.0030.0338.09
5.1.30.0060.0258.44
5.1.20.0050.0268.46
5.1.10.0060.0258.18
5.1.00.0060.0248.18
5.0.50.0040.0206.67
5.0.40.0050.0186.53
5.0.30.0030.0316.34
5.0.20.0020.0206.30
5.0.10.0000.0236.29
5.0.00.0010.0336.28
4.4.90.0030.0154.78
4.4.80.0010.0164.75
4.4.70.0020.0164.76
4.4.60.0020.0154.76
4.4.50.0030.0144.77
4.4.40.0010.0264.70
4.4.30.0040.0144.76
4.4.20.0030.0154.85
4.4.10.0030.0154.85
4.4.00.0030.0244.76
4.3.110.0000.0184.67
4.3.100.0030.0144.66
4.3.90.0030.0144.64
4.3.80.0030.0244.58
4.3.70.0030.0144.63
4.3.60.0030.0144.63
4.3.50.0040.0144.63
4.3.40.0030.0234.54
4.3.30.0020.0153.32
4.3.20.0030.0153.30
4.3.10.0030.0193.26
4.3.00.0030.02018.23

preferences:
38.16 ms | 401 KiB | 5 Q