3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myVar = "My sister alannis Is not That blonde, here is a good place. I know Ariane is not MY SISTER!"; echo "$myVar\n"; $myWords = [ ["is", "é"], ["on", "no"], ["that", "aquela"], ["sister", "irmã"], ["my", "minha"], ["myth", "mito"], ["he", "ele"], ["good", "bom"], ["ace", "perito"], ["i", "eu"] // notice I must be lowercase ]; $translations = array_column($myWords, 1, 0); // or skip this step and just declare $myWords as key-value pairs // length sorting is not necessary // preg_quote() and \Q\E are not used because dealing with words only (no danger of misinterpretation by regex) $pattern = '/\b(?>' . implode('|', array_keys($translations)) . ')\b/i'; // atomic group is slightly faster (no backtracking) /* echo $pattern; makes: /\b(?>is|on|that|sister|my|myth|he|good|ace)\b/i demo: https://regex101.com/r/DXTtDf/1 */ $translated = preg_replace_callback( $pattern, function($m) use($translations) { // bring $translations (lookup) array to function $encoding = 'UTF-8'; // default setting $key = mb_strtolower($m[0], $encoding); // standardize keys' case for lookup accessibility if (ctype_lower($m[0])) { // treat as all lower return $translations[$m[0]]; } elseif (mb_strlen($m[0], $encoding) > 1 && ctype_upper($m[0])) { // treat as all uppercase return mb_strtoupper($translations[$key], $encoding); } else { // treat as only first character uppercase return mb_strtoupper(mb_substr($translations[$key], 0, 1, $encoding), $encoding) // uppercase first . mb_substr($translations[$key], 1, mb_strlen($translations[$key], $encoding) - 1, $encoding); // append remaining lowercase } }, $myVar ); echo $translated;

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.4.120.0130.00824.32
8.4.110.0100.01018.27
8.4.100.0110.00319.14
8.4.90.0080.00818.91
8.4.80.0040.00518.90
8.4.70.0060.00218.27
8.4.60.0050.00418.97
8.4.50.0070.00118.92
8.4.40.0130.00617.83
8.4.30.0090.00922.22
8.4.20.0040.00718.16
8.4.10.0060.00318.17
8.3.250.0110.00718.85
8.3.240.0130.00619.20
8.3.230.0130.00716.60
8.3.220.0080.00719.11
8.3.210.0140.00516.79
8.3.200.0060.00216.86
8.3.190.0120.01017.13
8.3.180.0130.00717.16
8.3.170.0070.01120.66
8.3.160.0080.00017.16
8.3.150.0100.01017.38
8.3.140.0040.01116.66
8.3.130.0080.00018.50
8.3.120.0100.01018.89
8.3.110.0060.00316.63
8.3.100.0090.00024.06
8.3.90.0120.00326.77
8.3.80.0050.00516.63
8.3.70.0130.00916.58
8.3.60.0120.00616.63
8.3.50.0040.01118.41
8.3.40.0130.00719.05
8.3.30.0120.00618.80
8.3.20.0000.00724.18
8.3.10.0050.00324.66
8.3.00.0000.00726.16
8.2.290.0120.00620.14
8.2.280.0110.00818.48
8.2.270.0110.00719.37
8.2.260.0120.00318.63
8.2.250.0030.00618.46
8.2.240.0040.01119.01
8.2.230.0060.00320.94
8.2.220.0100.01037.54
8.2.210.0120.00626.77
8.2.200.0030.00616.75
8.2.190.0110.01116.75
8.2.180.0070.01425.92
8.2.170.0090.00619.13
8.2.160.0140.00022.96
8.2.150.0080.00025.66
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00820.02
8.2.110.0000.01122.43
8.2.100.0000.01117.83
8.2.90.0030.00518.16
8.2.80.0000.00819.11
8.2.70.0030.00617.88
8.2.60.0050.00517.92
8.2.50.0050.00318.07
8.2.40.0080.00018.28
8.2.30.0080.00017.90
8.2.20.0000.00819.52
8.2.10.0040.00418.97
8.2.00.0040.00419.45
8.1.330.0120.00822.22
8.1.320.0140.00518.31
8.1.310.0000.00816.96
8.1.300.0090.00918.00
8.1.290.0030.00618.88
8.1.280.0100.00725.92
8.1.270.0000.00823.99
8.1.260.0040.00726.35
8.1.250.0000.00828.09
8.1.240.0030.00622.48
8.1.230.0070.00420.97
8.1.220.0000.00817.74
8.1.210.0030.00518.83
8.1.200.0030.00617.59
8.1.190.0040.00417.48
8.1.180.0030.00618.10
8.1.170.0030.00618.84
8.1.160.0050.00319.03
8.1.150.0070.00018.92
8.1.140.0040.00417.73
8.1.130.0000.01017.82
8.1.120.0040.00417.71
8.1.110.0030.00617.70
8.1.100.0040.00417.63
8.1.90.0040.00417.58
8.1.80.0000.00917.61
8.1.70.0040.00417.64
8.1.60.0040.00417.70
8.1.50.0030.00617.74
8.1.40.0040.00417.65
8.1.30.0030.00617.88
8.1.20.0030.00617.75
8.1.10.0080.00017.77
8.1.00.0050.00217.75
8.0.300.0000.00720.16
8.0.290.0000.00716.88
8.0.280.0000.00718.52
8.0.270.0070.00017.04
8.0.260.0050.00216.96
8.0.250.0000.00717.18
8.0.240.0030.00317.05
8.0.230.0040.00417.04
8.0.220.0000.00717.14
8.0.210.0030.00317.06
8.0.200.0000.00717.17
8.0.190.0000.00817.16
8.0.180.0040.00417.11
8.0.170.0060.00317.16
8.0.160.0000.00817.05
8.0.150.0040.00417.08
8.0.140.0080.00316.95
8.0.130.0000.00613.51
8.0.120.0000.00917.12
8.0.110.0000.00817.00
8.0.100.0000.00817.01
8.0.90.0020.00517.11
8.0.80.0030.00516.99
8.0.70.0040.00417.09
8.0.60.0060.00317.13
8.0.50.0000.00817.15
8.0.30.0000.00817.03
8.0.20.0080.00017.17
8.0.10.0000.00817.18
8.0.00.0000.00817.04
7.4.330.0050.00015.55
7.4.320.0000.00716.79
7.4.300.0000.00616.88
7.4.290.0070.00016.74
7.4.280.0000.00716.76
7.4.270.0000.00716.88
7.4.260.0030.00313.59
7.4.250.0000.00816.83
7.4.240.0050.00516.92
7.4.230.0040.00416.71
7.4.220.0070.00016.92
7.4.210.0030.00516.83
7.4.200.0000.00816.73
7.4.190.0030.00316.86
7.4.180.0040.00416.72
7.4.160.0000.00816.95
7.4.150.0000.00716.84
7.4.140.0040.00416.88
7.4.130.0080.00016.77
7.4.120.0040.00416.79
7.4.110.0000.00716.76
7.4.100.0050.00217.00
7.4.90.0030.00316.70
7.4.80.0030.00316.80
7.4.70.0000.00716.72
7.4.60.0050.00316.75
7.4.50.0050.00316.73
7.4.40.0060.00316.75
7.4.30.0030.00616.94
7.4.20.0030.00516.78
7.4.10.0000.00916.81
7.4.00.0030.00616.78
7.3.330.0080.00016.50
7.3.320.0030.00313.64
7.3.310.0040.00416.63
7.3.300.0040.00416.74
7.3.290.0050.00216.39
7.3.280.0070.00016.39
7.3.270.0000.00716.61
7.3.260.0040.00416.45
7.3.250.0030.00316.64
7.3.240.0070.00016.61
7.3.230.0030.00316.37
7.3.220.0050.00316.30
7.3.210.0000.00816.34
7.3.200.0030.00316.35
7.3.190.0040.00416.54
7.3.180.0000.00716.57
7.3.170.0080.00016.41
7.3.160.0060.00316.53
7.3.150.0040.00416.52
7.3.140.0070.00216.49
7.3.130.0080.00016.48
7.3.120.0030.00316.44
7.3.110.0040.00416.55
7.3.100.0040.00416.56
7.3.90.0050.00316.70
7.3.80.0040.00416.55
7.3.70.0050.00216.73
7.3.60.0040.00416.69
7.3.50.0060.00316.72
7.3.40.0070.00016.68
7.3.30.0000.00716.62
7.3.20.0000.00718.45
7.3.10.0060.00218.50
7.3.00.0030.00618.47

preferences:
18.34 ms | 403 KiB | 5 Q