3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSearchResult($str, $query, $numOfWordToAdd) { $lowered = strtolower($query); $str = str_replace($query,$lowered,$str); list($before, $after) = explode($lowered, $str); $before = rtrim($before); $after = ltrim($after); $beforeArray = array_reverse(explode(" ", $before)); $afterArray = explode(" ", $after); $countBeforeArray = count($beforeArray); $countAfterArray = count($afterArray); $beforeString = ""; if($countBeforeArray < $numOfWordToAdd) { $beforeString = implode(' ', $beforeArray); } else { for($i = 0; $i < $numOfWordToAdd; $i++) { $beforeString = $beforeArray[$i] . ' ' . $beforeString; } } $afterString = ""; if($countAfterArray < $numOfWordToAdd) { $afterString = implode(' ', $afterArray); } else { for($i = 0; $i < $numOfWordToAdd; $i++) { $afterString = $afterString . $afterArray[$i] . ' '; } } $string = $beforeString . ' <span class="underline"> ' . $query . ' </span> ' . ' ' . $afterString; return $string; } $body = "<p>This is the body, KeyWoRd to be searched is here.</p>"; $keyword = "keyword"; echo getSearchResult($body,$keyword,1); ?>

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.00718.55
8.3.50.0110.00721.89
8.3.40.0060.00918.84
8.3.30.0110.00319.18
8.3.20.0030.00520.09
8.3.10.0060.00323.70
8.3.00.0040.00420.68
8.2.180.0120.00616.38
8.2.170.0100.01022.96
8.2.160.0070.00720.35
8.2.150.0080.00024.18
8.2.140.0030.00724.66
8.2.130.0180.00026.16
8.2.120.0080.00020.84
8.2.110.0050.00522.24
8.2.100.0030.00917.91
8.2.90.0000.00819.14
8.2.80.0030.00617.97
8.2.70.0050.00317.75
8.2.60.0030.00618.02
8.2.50.0060.00318.07
8.2.40.0030.00619.94
8.2.30.0070.00018.21
8.2.20.0000.00817.84
8.2.10.0050.00218.21
8.2.00.0080.00017.84
8.1.280.0110.00425.92
8.1.270.0060.00623.91
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0080.00023.92
8.1.230.0030.00719.16
8.1.220.0050.00317.79
8.1.210.0070.00318.77
8.1.200.0040.00417.36
8.1.190.0080.00017.22
8.1.180.0040.00418.10
8.1.170.0060.00318.66
8.1.160.0080.00022.01
8.1.150.0050.00218.66
8.1.140.0000.00717.47
8.1.130.0000.00717.76
8.1.120.0000.00717.51
8.1.110.0080.00017.51
8.1.100.0000.00717.42
8.1.90.0000.00717.48
8.1.80.0000.00817.38
8.1.70.0080.00017.46
8.1.60.0040.00517.49
8.1.50.0040.00417.46
8.1.40.0000.00717.51
8.1.30.0030.00617.57
8.1.20.0000.00817.58
8.1.10.0080.00017.53
8.1.00.0070.00017.38
8.0.300.0040.00420.51
8.0.290.0000.00816.75
8.0.280.0000.00718.45
8.0.270.0000.00717.28
8.0.260.0060.00017.34
8.0.250.0000.00716.99
8.0.240.0050.00317.01
8.0.230.0070.00017.04
8.0.220.0000.00716.97
8.0.210.0050.00216.94
8.0.200.0000.00717.09
8.0.190.0090.00016.99
8.0.180.0000.00717.01
8.0.170.0000.00816.99
8.0.160.0000.00717.00
8.0.150.0060.00516.81
8.0.140.0040.00416.93
8.0.130.0000.00613.48
8.0.120.0040.00416.80
8.0.110.0040.00417.00
8.0.100.0040.00416.97
8.0.90.0070.00016.98
8.0.80.0070.01416.97
8.0.70.0050.00216.96
8.0.60.0040.00416.98
8.0.50.0040.00417.04
8.0.30.0050.01417.10
8.0.20.0170.00917.40
8.0.10.0040.00416.95
8.0.00.0150.00416.81
7.4.330.0030.00315.14
7.4.320.0030.00316.60
7.4.300.0040.00416.58
7.4.290.0070.00016.67
7.4.280.0030.00516.53
7.4.270.0000.00716.46
7.4.260.0030.00616.53
7.4.250.0000.00716.48
7.4.240.0030.00416.56
7.4.230.0040.00416.53
7.4.220.0070.01116.71
7.4.210.0110.00316.70
7.4.200.0000.00716.61
7.4.160.0140.00716.37
7.4.150.0130.00917.40
7.4.140.0120.00717.86
7.4.130.0090.00716.68
7.4.120.0090.00916.51
7.4.110.0130.00316.57
7.4.100.0140.00316.60
7.4.90.0110.00616.68
7.4.80.0090.00919.39
7.4.70.0070.01416.57
7.4.60.0090.00916.68
7.4.50.0060.00316.65
7.4.40.0100.00716.54
7.4.30.0100.01016.48
7.4.00.0050.01215.13
7.3.330.0060.00013.28
7.3.320.0020.00213.44
7.3.310.0030.00316.39
7.3.300.0030.00316.43
7.3.290.0070.01116.41
7.3.280.0110.00616.44
7.3.270.0100.00617.40
7.3.260.0110.00616.66
7.3.250.0090.01016.50
7.3.240.0160.00716.58
7.3.230.0110.00716.45
7.3.210.0100.00716.39
7.3.200.0100.00619.39
7.3.190.0060.01316.53
7.3.180.0040.01116.45
7.3.170.0070.00716.41
7.3.160.0090.00616.52
7.3.120.0010.01115.06
7.3.110.0060.00615.04
7.3.100.0000.01514.80
7.3.90.0060.00315.03
7.3.80.0000.01014.96
7.3.70.0090.00314.99
7.3.60.0060.00614.91
7.3.50.0000.01115.09
7.3.40.0050.00514.84
7.3.30.0060.00714.96
7.3.20.0090.00616.60
7.3.10.0090.00616.53
7.3.00.0110.00616.22
7.2.330.0100.00716.63
7.2.320.0080.01116.44
7.2.310.0120.00616.65
7.2.300.0090.01216.88
7.2.290.0180.00016.48
7.2.250.0070.01115.16
7.2.240.0120.00815.09
7.2.230.0040.01115.02
7.2.220.0040.00815.36
7.2.210.0000.01915.19
7.2.200.0060.00615.05
7.2.190.0030.00615.02
7.2.180.0060.00915.07
7.2.170.0100.00015.04
7.2.130.0120.00616.66
7.2.120.0090.00616.32
7.2.110.0180.00417.06
7.2.100.0120.00616.51
7.2.90.0160.00616.34
7.2.80.0070.01116.86
7.2.70.0230.01016.70
7.2.60.0110.01416.66
7.2.50.0140.01016.77
7.2.40.0090.01216.48
7.2.30.0090.00616.90
7.2.20.0120.01216.61
7.2.10.0110.01116.69
7.2.00.0100.00718.19
7.1.330.0040.01115.65
7.1.320.0090.00315.53
7.1.310.0100.00715.53
7.1.300.0130.00016.01
7.1.290.0040.01115.66
7.1.280.0070.00715.64
7.1.270.0100.00315.99
7.1.260.0130.00315.83
7.1.250.0190.00916.01
7.1.100.0060.00818.29
7.1.70.0030.00717.10
7.1.60.0070.01819.70
7.1.50.0090.01516.99
7.1.00.0100.07022.29
7.0.200.0000.00716.82
7.0.140.0070.07022.19
7.0.110.0130.08720.07
7.0.100.0200.07019.98
7.0.90.0130.07720.00
7.0.80.0030.05020.01
7.0.70.0070.08319.95
7.0.60.0100.08319.95
7.0.50.0000.08720.46
7.0.40.0100.06720.20
7.0.30.0230.06320.25
7.0.20.0100.07020.27
7.0.10.0130.06020.23
7.0.00.0070.06720.14
5.6.280.0030.07320.94
5.6.250.0100.05720.70
5.6.240.0130.07320.73
5.6.230.0100.03720.71
5.6.220.0100.07020.85
5.6.210.0070.04720.57
5.6.200.0030.05721.15
5.6.190.0070.08721.16
5.6.180.0030.08020.94
5.6.170.0130.07021.23
5.6.160.0030.07320.96
5.6.150.0130.07321.10
5.6.140.0130.07721.13
5.6.130.0130.05721.12
5.6.120.0130.08021.00
5.6.110.0070.06721.03
5.6.100.0030.05021.26
5.6.90.0070.08321.12
5.6.80.0070.04320.39
5.6.70.0100.04320.54
5.6.60.0100.07720.52
5.6.50.0100.07020.34
5.6.40.0000.08020.63
5.6.30.0230.06320.59
5.6.20.0030.07320.58
5.6.10.0130.07020.59
5.6.00.0100.07320.29
5.5.380.0100.07720.54
5.5.370.0030.08020.30
5.5.360.0030.07020.41
5.5.350.0130.07020.17
5.5.340.0000.08320.98
5.5.330.0100.07020.89
5.5.320.0100.07720.80
5.5.310.0130.07720.75
5.5.300.0070.06020.70
5.5.290.0170.03721.03
5.5.280.0100.03720.82
5.5.270.0130.04020.80
5.5.260.0070.08021.04
5.5.250.0170.06320.61
5.5.240.0100.04020.24
5.5.230.0130.05720.33
5.5.220.0030.08720.34
5.5.210.0070.04720.20
5.5.200.0070.08020.18
5.5.190.0100.07020.21
5.5.180.0100.07720.25
5.5.160.0070.07320.35
5.5.150.0130.07020.40
5.5.140.0100.07320.31
5.5.130.0100.07020.30
5.5.120.0130.05020.33
5.5.110.0070.07720.16
5.5.100.0030.08320.16
5.5.90.0100.07320.22
5.5.80.0130.06720.20
5.5.70.0000.08720.08
5.5.60.0130.05320.05
5.5.50.0070.06720.05
5.5.40.0230.06020.25
5.5.30.0030.08020.14
5.5.20.0000.08320.14
5.5.10.0100.07720.13
5.5.00.0100.07019.93
5.4.450.0030.08319.36
5.4.440.0030.08019.32
5.4.430.0100.07719.31
5.4.420.0100.06319.35
5.4.410.0070.04319.19
5.4.400.0100.06318.97
5.4.390.0070.08319.09
5.4.380.0070.07019.00
5.4.370.0100.06319.16
5.4.360.0100.07319.18
5.4.350.0100.07019.02
5.4.340.0030.08719.18
5.4.320.0100.07719.31
5.4.310.0070.05719.20
5.4.300.0100.07719.22
5.4.290.0100.08719.03
5.4.280.0070.07319.21
5.4.270.0100.07719.15
5.4.260.0000.05019.22
5.4.250.0070.07719.14
5.4.240.0100.06719.08
5.4.230.0070.06719.03
5.4.220.0030.08019.09
5.4.210.0030.08019.01
5.4.200.0070.07319.22
5.4.190.0070.08019.21
5.4.180.0100.07718.99
5.4.170.0100.05019.32
5.4.160.0100.05018.98
5.4.150.0000.08719.04
5.4.140.0100.07016.45
5.4.130.0100.03316.44
5.4.120.0130.05016.55
5.4.110.0070.07316.55
5.4.100.0200.06016.46
5.4.90.0030.06016.50
5.4.80.0100.03716.50
5.4.70.0070.07316.31
5.4.60.0000.07716.64
5.4.50.0100.06716.44
5.4.40.0100.06716.57
5.4.30.0000.04316.47
5.4.20.0070.06316.57
5.4.10.0030.08016.53
5.4.00.0170.06715.80
5.3.290.0170.06714.78
5.3.280.0030.08314.61
5.3.270.0100.06714.62
5.3.260.0070.07014.75
5.3.250.0100.06314.62
5.3.240.0030.07014.65
5.3.230.0070.05714.70
5.3.220.0070.04314.58
5.3.210.0070.07014.58
5.3.200.0130.07014.55
5.3.190.0030.07314.44
5.3.180.0030.06714.44
5.3.170.0070.07314.81
5.3.160.0070.07314.57
5.3.150.0030.07314.59
5.3.140.0070.03714.59
5.3.130.0070.06314.57
5.3.120.0070.04314.59
5.3.110.0000.05314.79
5.3.100.0100.07314.20
5.3.90.0070.06314.17
5.3.80.0030.07013.89
5.3.70.0030.05314.03
5.3.60.0100.06714.00
5.3.50.0130.06714.05
5.3.40.0070.06714.10
5.3.30.0030.07314.05
5.3.20.0030.07313.71
5.3.10.0130.05313.70
5.3.00.0030.07013.78
5.2.170.0070.06311.16
5.2.160.0100.04711.13
5.2.150.0030.06011.16
5.2.140.0070.05011.16
5.2.130.0130.05011.34
5.2.120.0070.05711.26
5.2.110.0030.05711.09
5.2.100.0030.06011.21
5.2.90.0000.05311.34
5.2.80.0030.06711.34
5.2.70.0030.06711.10
5.2.60.0070.04711.14
5.2.50.0100.04710.99
5.2.40.0030.06011.23
5.2.30.0070.06711.00
5.2.20.0130.05710.97
5.2.10.0100.05710.85
5.2.00.0170.04710.74
5.1.60.0100.0479.97
5.1.50.0000.04710.07
5.1.40.0000.0479.98
5.1.30.0130.04710.35
5.1.20.0030.06010.50
5.1.10.0100.04710.06
5.1.00.0100.04710.04
5.0.50.0000.0508.54
5.0.40.0030.0438.41
5.0.30.0070.0538.40
5.0.20.0000.0438.30
5.0.10.0070.0438.35
5.0.00.0000.0638.30
4.4.90.0030.0338.30
4.4.80.0000.0378.30
4.4.70.0030.0338.30
4.4.60.0030.0308.30
4.4.50.0000.0378.30
4.4.40.0000.0608.30
4.4.30.0030.0278.30
4.4.20.0030.0338.30
4.4.10.0030.0338.30
4.4.00.0030.0538.30
4.3.110.0030.0178.30
4.3.100.0030.0278.30
4.3.90.0030.0208.30
4.3.80.0030.0538.30
4.3.70.0130.0238.30
4.3.60.0000.0408.30
4.3.50.0000.0378.30
4.3.40.0000.0508.30
4.3.30.0000.0378.30
4.3.20.0000.0408.30
4.3.10.0000.0408.30
4.3.00.0100.0378.30

preferences:
68.3 ms | 401 KiB | 5 Q