3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Removes the diacritical marks from a string. * * Diacritical marks: {@link https://unicode-table.com/blocks/combining-diacritical-marks/} * * @param string $string The string from which to strip the diacritical marks. * @return string Stripped string. */ function stripDiacriticalMarks(string $string): string { return preg_replace('/[\x{0300}-\x{036f}]/u', '', \Normalizer::normalize($string , \Normalizer::FORM_KD)); } /** * Checks if the string $haystack is like $needle, $needle can contain '%' and '_' * characters which will behave as if used in a SQL LIKE condition. Character escaping * is supported with '\'. * * @param string $haystack The string to check if it is like $needle * @param string $needle The string used to check if $haystack is like it * @param bool $ai Whether to check likeness in an accent-insensitive manner * @param bool $ci Whether to check likeness in a case-insensitive manner * @return bool True if $haystack is like $needle, otherwise, false */ function like(string $haystack, string $needle, bool $ai = true, bool $ci = true): bool { if ($ai) { $haystack = stripDiacriticalMarks($haystack); $needle = stripDiacriticalMarks($needle); } $needle = preg_quote($needle, '/'); $tokens = []; $needleLength = strlen($needle); for ($i = 0; $i < $needleLength;) { if ($needle[$i] === '\\') { $i += 2; if ($i < $needleLength) { if ($needle[$i] === '\\') { $tokens[] = '\\\\'; $i += 2; } else { $tokens[] = $needle[$i]; ++$i; } } else { $tokens[] = '\\\\'; } } else { switch ($needle[$i]) { case '_': $tokens[] = '.'; break; case '%': $tokens[] = '.*'; break; default: $tokens[] = $needle[$i]; break; } ++$i; } } return preg_match('/^' . implode($tokens) . '$/u' . ($ci ? 'i' : ''), $haystack) === 1; } /** * Escapes a string in a way that `UString::like` will match it as-is, thus '%' and '_' * would match a literal '%' and '_' respectively (and not behave as in a SQL LIKE * condition). * * @param string $str The string to escape. * @return string The escaped string. */ function escapeLike(string $str): string { return strtr($str, ['\\' => '\\\\', '%' => '\%', '_' => '\_']); } var_dump(like('Hello 🙃', 'Hello _')); var_dump(like('Hello 🙃', '_e%o__')); var_dump(like('asdfas \\🙃H\\\\%🙃É\\l\\_🙃\\l\\o asdfasf', '%' . escapeLike('\\🙃h\\\\%🙃e\\l\\_🙃\\l\\o') . '%'));

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.5.10.0100.00817.01
8.5.00.0070.01421.30
8.4.150.0010.00114.05
8.4.140.0300.01518.55
8.4.130.0120.00919.47
8.4.120.0160.00424.75
8.4.110.0050.00519.51
8.4.100.0130.00719.57
8.4.90.0130.00921.29
8.4.80.0070.00321.39
8.4.70.0050.00519.05
8.4.60.0190.00719.64
8.4.50.0050.00620.83
8.4.40.0090.01218.67
8.4.30.0130.00721.49
8.4.20.0170.00320.47
8.4.10.0100.01021.23
8.3.280.0140.00819.57
8.3.270.0100.01017.50
8.3.260.0050.00317.66
8.3.250.0100.01019.85
8.3.240.0120.00819.57
8.3.230.0120.00817.63
8.3.220.0050.00319.81
8.3.210.0120.00717.79
8.3.200.0100.00917.58
8.3.190.0090.00517.92
8.3.180.0130.00417.68
8.3.170.0070.01119.92
8.3.160.0120.00619.38
8.3.150.0110.00721.16
8.3.140.0040.01117.82
8.3.130.0000.01017.75
8.3.120.0140.00019.84
8.3.110.0050.00320.94
8.3.100.0030.00624.06
8.3.90.0030.00526.77
8.3.80.0100.00019.30
8.3.70.0150.00017.88
8.3.60.0220.00017.75
8.3.50.0080.00724.20
8.3.40.0140.00422.53
8.3.30.0120.00319.71
8.3.20.0000.00824.18
8.3.10.0080.00024.66
8.3.00.0080.00026.16
8.2.290.0120.00820.98
8.2.280.0060.00219.24
8.2.270.0150.00317.73
8.2.260.0110.00421.39
8.2.250.0050.00517.63
8.2.240.0130.00618.04
8.2.230.0040.00422.58
8.2.220.0060.00337.54
8.2.210.0090.00626.77
8.2.200.0100.00017.38
8.2.190.0090.00617.38
8.2.180.0090.00925.92
8.2.170.0120.00919.84
8.2.160.0110.00422.96
8.2.150.0060.00325.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00426.35
8.2.110.0070.00319.87
8.2.100.0060.00618.78
8.2.90.0040.00418.78
8.2.80.0080.00019.92
8.2.70.0080.00018.55
8.2.60.0000.00918.84
8.2.50.0040.00418.63
8.2.40.0040.00420.09
8.2.30.0040.00419.93
8.2.20.0050.00318.74
8.2.10.0000.00821.71
8.2.00.0020.00520.13
8.1.330.0130.00622.64
8.1.320.0100.00917.13
8.1.310.0110.00717.63
8.1.300.0030.00617.22
8.1.290.0070.01118.88
8.1.280.0180.01125.92
8.1.270.0080.00022.77
8.1.260.0060.00328.09
8.1.250.0000.00928.09
8.1.240.0040.00422.95
8.1.230.0140.00021.72
8.1.220.0050.00318.43
8.1.210.0050.00519.54
8.1.200.0040.00718.23
8.1.190.0040.00418.22
8.1.180.0030.00618.27
8.1.170.0000.00919.53
8.1.160.0040.00419.75
8.1.150.0040.00419.63
8.1.140.0020.00519.52
8.1.130.0070.00018.32
8.1.120.0040.00418.06
8.1.110.0050.00318.28
8.1.100.0040.00418.31
8.1.90.0000.00718.28
8.1.80.0000.00718.21
8.1.70.0000.00818.08
8.1.60.0000.00818.41
8.1.50.0080.00018.35
8.1.40.0000.00818.21
8.1.30.0040.00418.43
8.1.20.0000.00818.26
8.1.10.0040.00418.16
8.1.00.0040.00418.12
8.0.300.0000.00721.02
8.0.290.0000.00917.75
8.0.280.0000.00719.15
8.0.270.0050.00317.66
8.0.260.0000.00717.74
8.0.250.0040.00417.84
8.0.240.0030.00317.84
8.0.230.0020.00517.77
8.0.220.0040.00417.60
8.0.210.0050.00317.73
8.0.200.0040.00417.84
8.0.190.0000.00817.77
8.0.180.0030.00617.80
8.0.170.0060.00617.63
8.0.160.0040.00417.67
8.0.150.0040.00417.69
8.0.140.0040.00417.61
8.0.130.0030.00313.40
8.0.120.0000.00717.60
8.0.110.0030.00617.94
8.0.100.0030.00517.69
8.0.90.0050.00317.84
8.0.80.0030.01217.76
8.0.70.0000.00717.73
8.0.60.0000.00817.94
8.0.50.0030.00517.96
8.0.30.0120.00517.84
8.0.20.0180.00417.90
8.0.10.0040.01817.86
8.0.00.0060.01417.87
7.4.330.0000.00515.55
7.4.320.0060.00017.53
7.4.300.0000.00817.52
7.4.290.0000.00717.36
7.4.280.0030.00617.44
7.4.270.0000.00717.50
7.4.260.0000.00513.36
7.4.250.0070.00017.45
7.4.240.0040.00417.50
7.4.230.0070.00017.47
7.4.220.0020.00617.55
7.4.210.0040.01117.42
7.4.200.0020.00517.54
7.4.160.0090.00617.34
7.4.150.0030.01717.57
7.4.140.0130.00717.60
7.4.130.0080.01217.47
7.4.120.0060.01017.32
7.4.110.0120.00617.34
7.4.100.0060.01117.17
7.4.90.0100.00717.08
7.4.80.0130.00917.32
7.4.70.0030.01417.50
7.4.60.0050.01417.20
7.4.50.0090.01017.33
7.4.40.0120.00917.11
7.4.30.0080.00817.45
7.4.20.0080.01117.27
7.4.10.0110.00517.17
7.4.00.0090.00917.35
7.3.330.0100.00717.07
7.3.320.0080.00013.11
7.3.310.0000.00717.30
7.3.300.0030.00317.04
7.3.290.0080.00917.16
7.3.270.0070.01317.15
7.3.260.0090.01217.12
7.3.250.0000.01817.27
7.3.240.0140.00317.26
7.3.230.0110.00617.16
7.3.220.0110.00617.28
7.3.210.0040.01417.15
7.3.200.0100.01017.09
7.3.190.0110.00617.34
7.3.180.0070.01317.01
7.3.170.0180.00217.04
7.3.160.0110.00817.40
7.3.150.0060.01017.27
7.3.140.0090.00917.12
7.3.130.0100.00617.13
7.3.120.0120.00517.14
7.3.110.0110.01217.10
7.3.100.0100.01017.09
7.3.90.0110.00617.45
7.3.80.0110.00717.24
7.3.70.0070.01517.20
7.3.60.0110.01017.41
7.3.50.0150.00517.28
7.3.40.0140.01017.36
7.3.30.0130.00817.40
7.3.20.0110.00817.33
7.3.10.0140.00517.14
7.3.00.0080.01217.22
7.2.340.0140.00317.22
7.2.330.0100.00717.17
7.2.320.0120.00717.24
7.2.310.0180.00717.23
7.2.300.0140.00917.18
7.2.290.0150.00817.15
7.2.280.0100.01117.34
7.2.270.0130.00617.24
7.2.260.0130.01117.31
7.2.250.0130.01117.24
7.2.240.0170.00817.21
7.2.230.0180.00517.29
7.2.220.0130.01117.22
7.2.210.0090.01317.38
7.2.200.0100.01217.25
7.2.190.0070.01417.33
7.2.180.0120.00917.25
7.2.170.0150.01117.32
7.2.160.0150.00817.37
7.2.150.0090.01517.35
7.2.140.0270.00617.46
7.2.130.0280.01117.39
7.2.120.0160.00717.37
7.2.110.0110.01417.36
7.2.100.0120.01017.45
7.2.90.0150.00717.32
7.2.80.0130.00817.40
7.2.70.0110.01117.46
7.2.60.0120.00817.35
7.2.50.0240.00717.42
7.2.40.0110.01117.47
7.2.30.0200.00617.37
7.2.20.0110.01017.36
7.2.10.0110.01217.36
7.2.00.0060.01617.42
7.1.330.0200.01016.32
7.1.320.0300.00816.30
7.1.310.0170.01416.31
7.1.300.0150.01216.20
7.1.290.0200.00616.20
7.1.280.0180.01116.25
7.1.270.0290.00516.20
7.1.260.0170.00916.29
7.1.250.0140.01416.23
7.1.240.0260.00816.22
7.1.230.0130.01716.27
7.1.220.0200.00816.21
7.1.210.0200.01216.27
7.1.200.0230.00616.28
7.1.190.0150.01516.20
7.1.180.0280.00016.17
7.1.170.0180.01116.16
7.1.160.0370.00916.17
7.1.150.0260.00916.26
7.1.140.0190.00916.25
7.1.130.0220.00316.30
7.1.120.0140.01416.23
7.1.110.0160.00816.39
7.1.100.0200.00616.38
7.1.90.0740.00616.33
7.1.80.0210.00416.41
7.1.70.0170.00916.27
7.1.60.0190.00516.43
7.1.50.0150.00916.46
7.1.40.0290.00616.43
7.1.30.0190.01016.34
7.1.20.0260.00916.42
7.1.10.0420.01116.34
7.1.00.0940.00716.35
7.0.330.0230.00515.93
7.0.320.0200.01016.00
7.0.310.0240.00816.00
7.0.300.0170.00716.00
7.0.290.0190.00815.99
7.0.280.0420.01415.97
7.0.270.0090.01415.95
7.0.260.0210.00315.96
7.0.250.0170.01016.07
7.0.240.0160.00916.04
7.0.230.0160.00816.05
7.0.220.0120.01216.00
7.0.210.0160.01216.04
7.0.200.0180.00916.00
7.0.190.0150.00916.00
7.0.180.0170.00915.95
7.0.170.0210.00716.06
7.0.160.0170.01515.98
7.0.150.0210.00816.06
7.0.140.0160.01616.03
7.0.130.0230.00815.97
7.0.120.0150.01716.07
7.0.110.0210.00615.87
7.0.100.0200.00616.01
7.0.90.0120.01215.89
7.0.80.0200.00715.85
7.0.70.0270.00015.88
7.0.60.0160.01015.84
7.0.50.0090.01815.82
7.0.40.0040.01916.00
7.0.30.0300.00415.98
7.0.20.0140.01115.88
7.0.10.0180.00516.02
7.0.00.0160.01215.86
5.6.400.0210.00815.64
5.6.390.0170.01215.63
5.6.380.0180.01315.50
5.6.370.0260.00315.63
5.6.360.0230.00715.63
5.6.350.0290.00315.62
5.6.340.0180.00815.51
5.6.330.0180.00915.59
5.6.320.0160.01015.59
5.6.310.0250.00415.61
5.6.300.0120.00715.43
5.6.290.0260.00715.64
5.6.280.0210.00815.57
5.6.270.0140.01415.57
5.6.260.0220.00715.66
5.6.250.0230.00615.63
5.6.240.0120.01215.64
5.6.230.0220.00815.66
5.6.220.0200.01015.63
5.6.210.0220.00315.53
5.6.200.0190.01215.75
5.6.190.0150.01915.71
5.6.180.0170.01115.76
5.6.170.0110.01415.71
5.6.160.0190.01415.70
5.6.150.0200.01615.68
5.6.140.0190.01015.59
5.6.130.0110.01715.60
5.6.120.0160.01015.82
5.6.110.0180.00915.63
5.6.100.0280.00615.61
5.6.90.0200.00815.52
5.6.80.0170.01415.51
5.6.70.0180.01115.64
5.6.60.0130.01615.53
5.6.50.0250.00315.63
5.6.40.0210.00515.58
5.6.30.0200.01015.55
5.6.20.0120.01515.49
5.6.10.0120.01215.64
5.6.00.0210.00615.73
5.5.380.0190.01115.83
5.5.370.0120.01915.68
5.5.360.0100.01715.43
5.5.350.0210.00715.52
5.5.340.0150.01115.43
5.5.330.0200.00815.55
5.5.320.0150.01515.48
5.5.310.0180.00715.52
5.5.300.0220.00815.43
5.5.290.0160.01215.49
5.5.280.0110.01915.54
5.5.270.0210.00815.60
5.5.260.0250.00315.43
5.5.250.0160.01615.74
5.5.240.0190.01215.58
5.5.230.0210.00915.59
5.5.220.0180.01015.55
5.5.210.0150.01515.62
5.5.200.0060.02315.40
5.5.190.0200.00915.37
5.5.180.0090.01815.38
5.5.170.0390.01315.38
5.5.160.0150.01215.54
5.5.150.0150.01615.40
5.5.140.0170.00815.24
5.5.130.0190.01115.25
5.5.120.0110.02215.44
5.5.110.0250.01315.33
5.5.100.0120.01615.54
5.5.90.0210.00615.70
5.5.80.0210.00815.53
5.5.70.0190.01315.51
5.5.60.0280.00815.62
5.5.50.0240.00515.62
5.5.40.0200.00915.58
5.5.30.0180.01115.53
5.5.20.0230.00315.56
5.5.10.0130.01315.47
5.5.00.0240.00615.56
5.4.450.0070.01413.71
5.4.440.0250.00013.71
5.4.430.0200.00013.71
5.4.420.0130.00713.71
5.4.410.0170.00813.71
5.4.400.0180.00413.71
5.4.390.0110.01413.71
5.4.380.0100.01113.71
5.4.370.0130.00713.71
5.4.360.0150.00813.71
5.4.350.0140.00713.71
5.4.340.0120.00813.71
5.4.330.0220.00313.71
5.4.320.0100.01013.71
5.4.310.0150.00713.71
5.4.300.0100.00813.71
5.4.290.0210.00313.71
5.4.280.0080.01313.71
5.4.270.0150.00613.71
5.4.260.0150.00613.71
5.4.250.0110.01113.71
5.4.240.0130.01013.71
5.4.230.0090.01313.71
5.4.220.0170.00713.71
5.4.210.0130.00613.71
5.4.200.0200.00813.71
5.4.190.0180.00713.71
5.4.180.0220.00013.71
5.4.170.0190.00513.71
5.4.160.0170.00613.71
5.4.150.0120.00613.71
5.4.140.0140.00413.71
5.4.130.0210.00013.71
5.4.120.0260.00413.71
5.4.110.0000.01913.71
5.4.100.0100.01113.71
5.4.90.0110.00813.71
5.4.80.0150.00813.71
5.4.70.0130.00813.71
5.4.60.0140.01013.71
5.4.50.0150.00413.71
5.4.40.0130.00813.71
5.4.30.0100.01313.71
5.4.20.0120.01213.71
5.4.10.0240.00013.71
5.4.00.0170.00713.71
5.3.290.0200.00813.71
5.3.280.0150.00713.71
5.3.270.0110.00813.71
5.3.260.0170.00813.71
5.3.250.0150.00613.71
5.3.240.0180.00413.71
5.3.230.0170.00513.71
5.3.220.0140.00613.71
5.3.210.0140.00913.71
5.3.200.0140.01113.71
5.3.190.0100.01013.71
5.3.180.0190.01013.71
5.3.170.0180.00613.71
5.3.160.0150.00913.71
5.3.150.0180.00513.71
5.3.140.0130.01013.71
5.3.130.0240.00813.71
5.3.120.0110.01113.71
5.3.110.0190.00313.71
5.3.100.0180.00413.71
5.3.90.0140.00513.71
5.3.80.0130.00713.71
5.3.70.0190.00413.71
5.3.60.0100.01013.71
5.3.50.0150.00613.71
5.3.40.0040.01813.71
5.3.30.0120.00913.71
5.3.20.0170.00713.71
5.3.10.0280.00613.71
5.3.00.0170.00413.71
5.2.170.0160.00413.71
5.2.160.0110.00713.71
5.2.150.0140.00613.71
5.2.140.0130.01013.71
5.2.130.0080.01313.71
5.2.120.0110.00813.71
5.2.110.0130.01013.71
5.2.100.0100.01013.71
5.2.90.0130.00713.71
5.2.80.0110.00813.71
5.2.70.0080.00813.71
5.2.60.0130.00313.71
5.2.50.0110.01113.71
5.2.40.0030.01313.71
5.2.30.0050.01313.71
5.2.20.0120.00913.71
5.2.10.0040.01113.71
5.2.00.0100.00513.71
5.1.60.0090.00413.71
5.1.50.0110.00413.71
5.1.40.0070.01113.71
5.1.30.0140.00613.71
5.1.20.0080.00813.71
5.1.10.0130.00713.71
5.1.00.0040.01313.71
5.0.50.0090.00313.71
5.0.40.0080.00813.71
5.0.30.0090.00313.71
5.0.20.0080.00513.71
5.0.10.0150.01013.71
5.0.00.0080.00413.71
4.4.90.0080.00013.71
4.4.80.0110.00013.71
4.4.70.0060.00513.71
4.4.60.0050.00213.71
4.4.50.0060.00313.71
4.4.40.0070.00313.71
4.4.30.0030.00613.71
4.4.20.0060.00613.71
4.4.10.0000.00813.71
4.4.00.0080.00013.71
4.3.110.0080.00013.71
4.3.100.0070.00013.71
4.3.90.0060.00313.71
4.3.80.0070.00413.71
4.3.70.0000.00813.71
4.3.60.0100.00013.71
4.3.50.0070.00413.71
4.3.40.0060.00613.71
4.3.30.0060.00013.71
4.3.20.0090.00013.71
4.3.10.0070.00013.71
4.3.00.0040.00413.71

preferences:
173.25 ms | 403 KiB | 5 Q