3v4l.org

run code in 300+ PHP versions simultaneously
<?php $articles = [ (object)['text' => 'Some text {reillorama:5/dots/1} some text {reillorama:12/foo}'], (object)['text' => 'Only text with no placeholders'], (object)['text' => 'Some text {reillorama:33} some text {reillorama:1/bar} some text'], (object)['text' => 'Some text {reillorama:5/word} some text {reillorama:2} some text {reillorama:555555/noSpacesInWord/7777777}'], (object)['text' => 'The pattern also allows the middle parameter to be omitted {reillorama:6/7}'], ]; $firstLookup = [5 => 'five', 12 => 'twelve', 1 => 'one', 2 => 'two']; $secondLookup = ['foo' => 'fighters', 'bar' => 'none', 'word' => 'up', 'noSpacesInWord' => 'replacement']; $thirdLookup = [1 => 'another one', 7 => 'seven']; foreach ($articles as $article) { $article->text = preg_replace_callback( '~{reillorama:(\d+)(?:/([a-z]+))?(?:/(\d+))?}~i', function($m) use ($firstLookup, $secondLookup, $thirdLookup) { return '**' . ($firstLookup[$m[1]] ?? '[first not found]') . ($m[2] === null ? '' : (isset($secondLookup[$m[2]]) ? $secondLookup[$m[2]] : '[second not found]')) . ($m[3] === null ? '' : (isset($thirdLookup[$m[3]]) ? $thirdLookup[$m[3]] : '[third not found]')) . '**'; //var_export($m); if you want to see what is in the matches array }, $article->text, -1, $count, PREG_UNMATCHED_AS_NULL ); echo "{$article->text}\n---\n"; }

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.0090.01218.39
8.3.50.0110.01120.14
8.3.40.0150.00019.21
8.3.30.0120.00319.17
8.3.20.0000.00824.18
8.3.10.0000.00924.66
8.3.00.0050.00326.16
8.2.180.0090.00625.92
8.2.170.0100.00619.06
8.2.160.0170.00022.96
8.2.150.0080.00825.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0050.00226.16
8.2.110.0000.01020.70
8.2.100.0040.00817.97
8.2.90.0000.00818.28
8.2.80.0050.00317.97
8.2.70.0000.01017.88
8.2.60.0030.00717.93
8.2.50.0000.00818.07
8.2.40.0090.00018.22
8.2.30.0000.01018.20
8.2.20.0040.00419.48
8.2.10.0000.00718.04
8.2.00.0000.00819.36
8.1.280.0040.01925.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.00923.97
8.1.230.0100.00317.61
8.1.220.0090.00017.78
8.1.210.0030.00518.77
8.1.200.0070.00317.72
8.1.190.0050.00517.38
8.1.180.0040.00418.10
8.1.170.0040.00418.84
8.1.160.0030.00918.96
8.1.150.0060.00318.85
8.1.140.0000.00717.65
8.1.130.0000.00718.87
8.1.120.0000.00717.72
8.1.110.0040.00417.63
8.1.100.0000.00717.65
8.1.90.0000.00917.70
8.1.80.0000.00717.51
8.1.70.0000.00717.70
8.1.60.0000.00917.76
8.1.50.0050.00317.72
8.1.40.0000.00717.75
8.1.30.0000.00917.79
8.1.20.0060.00317.77
8.1.10.0050.00317.77
8.1.00.0000.00917.66
8.0.300.0060.00320.21
8.0.290.0070.00716.63
8.0.280.0070.00018.52
8.0.270.0000.00717.01
8.0.260.0060.00018.39
8.0.250.0000.00817.20
8.0.240.0040.00417.21
8.0.230.0050.00317.20
8.0.220.0050.00217.16
8.0.210.0000.00717.21
8.0.200.0070.00017.24
8.0.190.0030.00517.27
8.0.180.0040.00417.17
8.0.170.0000.00917.18
8.0.160.0040.00417.21
8.0.150.0030.00617.09
8.0.140.0070.00017.08
8.0.130.0180.00917.11
8.0.120.0200.00417.16
8.0.110.0170.00517.14
8.0.100.0230.00317.16
8.0.90.0200.00417.05
8.0.80.0130.00017.20
8.0.70.0000.01417.01
8.0.60.0170.00817.14
8.0.50.0160.00817.07
8.0.30.0220.00617.18
8.0.20.0200.00817.19
8.0.10.0150.00917.18
8.0.00.0040.01217.25
7.4.330.0000.00515.55
7.4.320.0070.00016.63
7.4.300.0000.00716.91
7.4.290.0000.00716.79
7.4.280.0000.00716.70
7.4.270.0000.00816.77
7.4.260.0140.00016.75
7.4.250.0150.01316.71
7.4.240.0200.00816.84
7.4.230.0150.01216.74
7.4.220.0200.00316.71
7.4.210.0190.00416.68
7.4.200.0190.00416.84
7.4.190.0160.00716.81
7.4.180.0180.00516.96
7.4.160.0140.00916.82
7.4.150.0160.00716.79
7.4.140.0200.00316.79
7.4.130.0170.00516.90
7.4.120.0190.00416.78
7.4.110.0200.00316.83
7.4.100.0170.00716.82
7.4.90.0190.00416.79
7.4.80.0200.00316.76
7.4.70.0120.01116.67
7.4.60.0170.00516.70
7.4.50.0200.00316.79
7.4.40.0130.00916.64
7.4.30.0060.01616.64
7.4.20.0190.00416.51
7.4.10.0200.00216.62
7.4.00.0170.00516.58
7.3.330.0230.00016.47
7.3.320.0130.01016.23
7.3.310.0210.00316.51
7.3.300.0140.01116.55
7.3.290.0190.00816.27
7.3.280.0210.00416.17
7.3.270.0210.00416.40
7.3.260.0170.00716.46
7.3.250.0210.00316.43
7.3.240.0160.00416.43
7.3.230.0070.00416.41
7.3.220.0120.00516.32
7.3.210.0210.00416.44
7.3.200.0180.00516.48
7.3.190.0150.00716.50
7.3.180.0150.00716.43
7.3.170.0160.00816.41
7.3.160.0240.00316.27
7.3.150.0200.00316.42
7.3.140.0200.00416.46
7.3.130.0200.00416.34
7.3.120.0210.00316.37
7.3.110.0160.00716.12
7.3.100.0140.00516.04
7.3.90.0090.00316.49
7.3.80.0140.00316.09
7.3.70.0140.00716.39
7.3.60.0070.00716.36
7.3.50.0160.00316.54
7.3.40.0120.00616.36
7.3.30.0120.00316.55
7.3.20.0140.00016.59
7.3.10.0070.00716.29
7.3.00.0040.00816.45

preferences:
56.47 ms | 401 KiB | 5 Q