3v4l.org

run code in 300+ PHP versions simultaneously
<?php // all keys must be lowercase $keywords_external_path = array( "sweet potato" => "food/sweet-potato", "potato salads" => "food/potato-salads", "potato" => "food/potato", ); $data = array( 'post_content' => 'Sweet potato some text then potato then more text and then potato salads' ); $base = 'http://domain.com/'; // only if this is useful $keywords_external = array_keys($keywords_external_path); krsort($keywords_external); // to quickly discards useless position (if you have many keywords): you can also do the same with the second letter $keywords_first_letter = implode('', array_unique(array_reduce($keywords_external, function ($c, $i) { $c[]=$i[0]; return $c; }, []))); $pattern = '~\b(?=['. $keywords_first_letter . '])(?:' . implode('|', $keywords_external) . ')\b~i'; $result = preg_replace_callback($pattern, function ($m) use ($keywords_external_path, $base) { return '<a href="' . $base . $keywords_external_path . '">' . $m[0] . '</a>'; }, $data['post_content']); echo $result;

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.56
8.3.50.0110.01516.66
8.3.40.0070.00719.09
8.3.30.0070.00719.21
8.3.20.0040.00420.35
8.3.10.0040.00421.66
8.3.00.0050.00320.89
8.2.180.0090.00618.91
8.2.170.0070.00722.96
8.2.160.0060.00922.21
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00722.20
8.2.120.0000.00826.35
8.2.110.0060.00322.25
8.2.100.0040.00718.16
8.2.90.0060.00319.20
8.2.80.0040.00418.00
8.2.70.0030.00617.75
8.2.60.0050.00318.16
8.2.50.0000.00718.16
8.2.40.0000.00720.59
8.2.30.0040.00419.43
8.2.20.0040.00418.31
8.2.10.0000.00818.32
8.2.00.0040.00418.23
8.1.280.0090.00925.92
8.1.270.0050.00323.92
8.1.260.0040.00426.35
8.1.250.0000.00928.09
8.1.240.0050.00521.12
8.1.230.0080.00319.17
8.1.220.0040.00417.91
8.1.210.0000.00918.77
8.1.200.0030.00717.60
8.1.190.0040.00417.60
8.1.180.0080.00018.10
8.1.170.0100.00018.56
8.1.160.0050.00218.96
8.1.150.0070.00020.08
8.1.140.0000.00819.70
8.1.130.0040.00418.89
8.1.120.0000.00717.64
8.1.110.0070.00017.56
8.1.100.0080.00017.68
8.1.90.0000.00717.68
8.1.80.0050.00217.58
8.1.70.0030.00317.64
8.1.60.0000.00817.77
8.1.50.0030.00517.61
8.1.40.0000.00717.72
8.1.30.0030.00517.91
8.1.20.0040.00417.73
8.1.10.0040.00417.80
8.1.00.0090.00017.66
8.0.300.0000.00820.21
8.0.290.0040.00417.00
8.0.280.0070.00018.38
8.0.270.0050.00317.35
8.0.260.0030.00317.11
8.0.250.0070.00017.21
8.0.240.0040.00417.25
8.0.230.0000.00717.18
8.0.220.0000.00817.28
8.0.210.0000.00717.09
8.0.200.0030.00317.18
8.0.190.0070.00717.10
8.0.180.0040.00417.14
8.0.170.0030.00517.20
8.0.160.0000.00717.02
8.0.150.0050.00317.15
8.0.140.0000.00717.08
8.0.130.0050.00013.54
8.0.120.0000.00817.21
8.0.110.0000.00817.14
8.0.100.0040.00417.08
8.0.90.0070.00017.19
8.0.80.0060.00917.20
8.0.70.0080.00017.09
8.0.60.0040.00417.19
8.0.50.0040.00417.10
8.0.30.0070.01117.27
8.0.20.0100.01117.40
8.0.10.0040.00417.19
8.0.00.0120.00917.14
7.4.330.0040.00415.55
7.4.320.0030.00316.79
7.4.300.0030.00316.84
7.4.290.0070.00316.73
7.4.280.0070.00016.70
7.4.270.0000.00716.88
7.4.260.0000.00613.57
7.4.250.0040.00416.88
7.4.240.0000.00716.89
7.4.230.0000.00716.60
7.4.220.0060.01616.88
7.4.210.0060.01216.78
7.4.200.0030.00516.81
7.4.160.0060.01016.81
7.4.150.0110.00717.40
7.4.140.0090.00917.86
7.4.130.0130.00616.76
7.4.120.0100.01416.89
7.4.110.0070.01116.79
7.4.100.0130.00916.66
7.4.90.0190.00316.86
7.4.80.0130.01019.39
7.4.70.0000.01616.85
7.4.60.0110.00716.69
7.4.50.0070.01116.73
7.4.40.0080.00816.67
7.4.30.0100.01116.79
7.4.00.0060.00815.35
7.3.330.0050.00013.52
7.3.320.0000.00613.68
7.3.310.0030.00316.51
7.3.300.0000.00716.63
7.3.290.0050.00916.56
7.3.280.0080.00816.55
7.3.270.0150.00317.40
7.3.260.0070.01416.66
7.3.250.0130.00716.86
7.3.240.0110.00616.70
7.3.230.0080.01016.84
7.3.210.0060.01016.78
7.3.200.0090.00616.76
7.3.190.0080.00816.60
7.3.180.0070.01016.54
7.3.170.0110.00616.63
7.3.160.0090.01216.85
7.3.120.0000.01515.25
7.3.110.0060.00515.30
7.3.100.0070.00715.00
7.3.90.0110.00714.78
7.3.80.0150.00415.01
7.3.70.0070.00715.11
7.3.60.0040.00815.16
7.3.50.0090.00615.19
7.3.40.0060.00614.91
7.3.30.0060.00915.09
7.3.20.0000.01516.70
7.3.10.0100.00316.92
7.3.00.0000.00916.94
7.2.330.0060.01216.63
7.2.320.0150.00316.88
7.2.310.0150.00617.04
7.2.300.0070.01016.91
7.2.290.0090.00916.96
7.2.250.0040.01515.40
7.2.240.0070.01115.37
7.2.230.0100.01015.28
7.2.220.0060.00615.43
7.2.210.0070.01115.51
7.2.200.0000.00915.29
7.2.190.0060.01215.23
7.2.180.0030.01015.32
7.2.170.0040.01215.14
7.2.60.0110.00316.96
7.2.50.0060.00617.08
7.1.330.0030.01016.06
7.1.320.0100.00315.98
7.1.310.0100.00715.99
7.1.300.0030.01315.94
7.1.290.0050.00515.71
7.1.280.0000.01715.69
7.1.270.0090.00616.03
7.1.260.0000.01216.13
7.1.200.0030.00916.03
7.1.70.0040.00417.39
7.1.60.0600.01733.57
7.1.50.0530.01333.13
7.1.40.0600.02032.83
7.1.30.0800.01332.84
7.1.20.0870.01332.99
7.1.10.0500.01015.08
7.1.00.0530.01315.22
7.0.200.0370.01314.88
7.0.190.0430.01014.95
7.0.180.0670.01314.70
7.0.170.0430.01314.42
7.0.160.0470.01314.67
7.0.150.0370.01014.63
7.0.140.0400.01014.72
7.0.130.0370.01014.85
7.0.120.0330.01015.09
7.0.110.0370.01714.75
7.0.100.0500.01014.97
7.0.90.0470.01014.81
7.0.80.0570.01014.85
7.0.70.0430.01714.96
7.0.60.0570.01314.59
7.0.50.0270.01314.65
7.0.40.0330.00714.66
7.0.30.0300.01014.96
7.0.20.0370.01014.71
7.0.10.0430.00714.73
7.0.00.0270.02014.85

preferences:
30.41 ms | 400 KiB | 5 Q