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[strtolower($m[0])] . '">' . $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.0110.01118.80
8.3.50.0140.01116.57
8.3.40.0070.00719.09
8.3.30.0110.00418.90
8.3.20.0000.00820.20
8.3.10.0040.00421.98
8.3.00.0040.00420.95
8.2.180.0040.01118.53
8.2.170.0150.00022.96
8.2.160.0040.01122.29
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0040.00420.39
8.2.120.0000.00826.35
8.2.110.0070.00320.47
8.2.100.0090.00317.97
8.2.90.0050.00319.30
8.2.80.0000.00817.97
8.2.70.0000.00817.75
8.2.60.0050.00318.16
8.2.50.0050.00318.10
8.2.40.0000.00720.57
8.2.30.0040.00419.53
8.2.20.0040.00418.19
8.2.10.0050.00318.37
8.2.00.0020.00518.41
8.1.280.0120.00625.92
8.1.270.0040.00424.01
8.1.260.0060.00326.35
8.1.250.0030.00628.09
8.1.240.0030.00622.32
8.1.230.0110.00022.26
8.1.220.0000.00818.03
8.1.210.0050.00318.77
8.1.200.0000.00917.73
8.1.190.0040.00417.50
8.1.180.0060.00318.10
8.1.170.0020.00718.58
8.1.160.0000.00719.01
8.1.150.0040.00420.20
8.1.140.0040.00419.75
8.1.130.0050.00318.97
8.1.120.0000.00717.65
8.1.110.0040.00417.66
8.1.100.0040.00417.55
8.1.90.0030.00517.62
8.1.80.0040.00417.64
8.1.70.0030.00317.57
8.1.60.0040.00417.59
8.1.50.0080.00017.74
8.1.40.0080.00017.63
8.1.30.0060.00317.80
8.1.20.0080.00017.76
8.1.10.0000.00717.70
8.1.00.0000.00817.68
8.0.300.0080.00018.77
8.0.290.0080.00017.00
8.0.280.0070.00018.51
8.0.270.0070.00017.30
8.0.260.0050.00316.92
8.0.250.0000.00717.14
8.0.240.0000.00817.00
8.0.230.0030.00417.11
8.0.220.0000.00717.08
8.0.210.0000.00717.15
8.0.200.0050.00317.05
8.0.190.0070.00717.16
8.0.180.0060.00317.02
8.0.170.0050.00317.13
8.0.160.0000.00717.00
8.0.150.0070.00016.94
8.0.140.0040.00416.98
8.0.130.0000.00513.40
8.0.120.0080.00017.01
8.0.110.0060.00317.02
8.0.100.0070.00017.13
8.0.90.0000.00717.18
8.0.80.0100.00617.07
8.0.70.0000.00817.20
8.0.60.0000.00717.16
8.0.50.0050.00317.24
8.0.30.0090.00817.28
8.0.20.0140.00717.40
8.0.10.0050.00217.09
8.0.00.0060.01217.09
7.4.330.0030.00215.55
7.4.320.0030.00316.79
7.4.300.0000.00716.82
7.4.290.0060.00316.81
7.4.280.0060.00316.92
7.4.270.0030.00316.89
7.4.260.0070.00013.59
7.4.250.0000.01016.82
7.4.240.0000.00716.76
7.4.230.0030.00316.98
7.4.220.0060.01316.85
7.4.210.0100.00716.77
7.4.200.0000.00716.97
7.4.160.0100.00816.58
7.4.150.0140.00317.40
7.4.140.0070.01117.86
7.4.130.0220.00316.80
7.4.120.0130.00516.77
7.4.110.0070.01116.68
7.4.100.0070.01016.85
7.4.90.0070.01016.81
7.4.80.0150.00319.39
7.4.70.0130.00316.77
7.4.60.0100.00716.78
7.4.50.0000.01416.54
7.4.40.0120.00416.92
7.4.30.0100.00616.71
7.4.00.0100.00715.17
7.3.330.0000.00513.58
7.3.320.0030.00313.37
7.3.310.0030.00316.57
7.3.300.0000.00716.53
7.3.290.0050.01016.46
7.3.280.0080.00816.47
7.3.270.0120.00917.40
7.3.260.0150.00316.57
7.3.250.0050.01516.71
7.3.240.0120.00516.56
7.3.230.0140.00316.85
7.3.210.0130.00316.64
7.3.200.0120.01016.80
7.3.190.0070.01016.63
7.3.180.0030.01316.58
7.3.170.0060.01116.54
7.3.160.0120.00916.65
7.3.120.0050.01315.17
7.3.110.0090.01115.01
7.3.100.0090.00814.98
7.3.90.0080.01015.24
7.3.80.0060.00914.88
7.3.70.0050.00915.18
7.3.60.0050.01014.97
7.3.50.0050.01015.11
7.3.40.0080.00815.16
7.3.30.0050.00715.01
7.3.20.0050.00816.83
7.3.10.0090.00516.86
7.3.00.0080.00716.75
7.2.330.0100.00716.92
7.2.320.0090.00916.76
7.2.310.0060.01016.81
7.2.300.0030.01316.97
7.2.290.0090.01117.07
7.2.250.0020.01415.26
7.2.240.0150.00515.37
7.2.230.0080.00915.21
7.2.220.0050.00615.15
7.2.210.0060.00615.42
7.2.200.0000.01515.39
7.2.190.0050.00715.44
7.2.180.0050.00815.14
7.2.170.0060.00915.30
7.2.80.0040.00816.82
7.2.60.0030.00916.73
7.2.00.0000.01519.57
7.1.330.0060.00815.99
7.1.320.0090.00316.04
7.1.310.0050.00815.93
7.1.300.0030.00716.12
7.1.290.0030.00915.87
7.1.280.0050.00516.12
7.1.270.0050.01215.70
7.1.260.0050.00915.84
7.1.200.0040.00715.93
7.1.100.0000.01118.41
7.1.70.0020.00517.45
7.1.60.0330.02333.62
7.1.50.0530.01333.23
7.1.40.0630.02032.87
7.1.30.0730.01332.79
7.1.20.0470.01733.03
7.1.10.0500.01314.88
7.1.00.0300.01015.06
7.0.200.0370.01014.87
7.0.190.0370.01315.14
7.0.180.0470.02314.54
7.0.170.0370.00714.69
7.0.160.0330.01014.54
7.0.150.0270.01314.53
7.0.140.0300.01314.83
7.0.130.0330.01314.83
7.0.120.0370.01014.96
7.0.110.0330.01714.89
7.0.100.0300.01314.79
7.0.90.0270.01314.71
7.0.80.0270.01314.85
7.0.70.0430.01314.65
7.0.60.0600.00714.42
7.0.50.0300.01314.69
7.0.40.0370.00715.06
7.0.30.0270.01715.07
7.0.20.0430.01314.77
7.0.10.0430.01714.77
7.0.00.0300.01014.75

preferences:
54.12 ms | 401 KiB | 5 Q