3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * Some sophisticated tests against PHP's mb_detect_encoding() function, * testing ASCII, ISO-8859-1, Windows-1252, UTF-8 and UTF-16 in both byte orders. * * Tim Weber, 2014-07-04 */ $samples = array( 'ASCII only' => array( 'string' => 'Hallo', 'valid' => 'A 1252 L1 U8', // invalid in UTF-16: odd number of bytes ), 'ASCII with null in the middle' => array( 'string' => "Hal\x00lo.", 'valid' => 'A 1252 L1 U8', // invalid in UTF-16: odd number ), '8-bit string with character not in Windows-1252' => array( 'string' => "Hal\x81lo", // 0x80 and 0x82 are used in 1252, 0x81 not 'valid' => 'L1 U16B U16L', // valid in UTF-16 ), 'UTF-8 with a 2-byte BMP character' => array( 'string' => "Hall\xc3\xb6.", // Hallö. 'valid' => '1252 L1 U8', ), 'UTF-8 with a 3-byte BMP character' => array( 'string' => "Hal\xef\xbb\xbflo.", // Hal<U+FEFF>lo. 'valid' => '1252 L1 U8', ), 'UTF-8 with a 4-byte SP character' => array( 'string' => "Oh \xf0\x9f\x92\xa9!", // Oh <F+1F4A9 (pile of poo)>! 'valid' => '1252 L1 U8 U16B U16L', ), 'UTF-8 with a really high PUA-B character' => array( 'string' => "(\xf4\x8f\xbf\xba)", // (<U+10FFFA>) 'valid' => 'L1 U8 U16B U16L', // Invalid in 1252 b/c of 0x8f ), 'single surrogate lead in UTF-8' => array( 'string' => "\xed\xa0\x82", // (<U+D802>) 'valid' => '1252 L1', ), 'single surrogate lead in UTF-16BE' => array( 'string' => "\xd8\x02", // (<U+D802>) 'valid' => '1252 L1 U16L', ), 'single surrogate trail in UTF-8' => array( 'string' => "\xed\xb0\x82", // (<U+DC02>) 'valid' => '1252 L1', ), 'single surrogate trail in UTF-16LE' => array( 'string' => "\x02\xdc", // (<U+DC02>) 'valid' => '1252 L1 U16B', ), 'Plane 17 UTF-8 character' => array( 'string' => "\xf4\x92\x8d\x85", // (<U+11234>) 'valid' => 'L1 U16B U16L', // Invalid in 1252 b/c of 0x8d ), 'null character encoded in two UTF-8 bytes' => array( 'string' => "\xc0\x80", // <U+0000> 'valid' => '1252 L1 U16B U16L', ), 'UTF-8 with a BMP non-shortest sequence (3 instead of 2 bytes)' => array( 'string' => "Hall\xe0\x83\xb6.", // Hallö. 'valid' => '1252 L1 U16B U16L', ), 'UTF-16BE of an ASCII character' => array( 'string' => "\x00\x79", // y 'valid' => 'ASCII 1252 L1 U8 U16B U16L', ), 'UTF-16LE of an SMP character' => array( 'string' => "\x34\xd8\x1e\xdd", // <U+1D11E (musical symbol g clef)> 'valid' => '1252 L1 U16B U16L', ), 'UTF-16BE BOM' => array( 'string' => "\xfe\xff", // <U+FEFF> 'valid' => '1252 L1 U16B U16L', // U+FFFE is _not_ an invalid codepoint, therefore valid U16L ), 'UTF-16LE SP character' => array( 'string' => "\x3d\xd8\xa9\xdc", // <U+1F4A9> 'valid' => '1252 L1 U16L U16B', ), 'UTF-16BE SP character that is lone surrogate lead in UTF-16LE' => array( 'string' => "\xd8\x34\xdd\xd8", // <U+1D1D8 (musical symbol torculus> 'valid' => '1252 L1 U16B', ), ); $encoding_mappings = array( 'ASCII' => 'A', 'Windows-1252' => '1252', 'ISO-8859-1' => 'L1', 'UTF-8' => 'U8', 'UTF-16BE' => 'U16B', 'UTF-16LE' => 'U16L', ); $encodings = array_keys($encoding_mappings); foreach ($samples as $name => &$data) { // Convert string "valid" to array. if (is_string($data['valid'])) { $data['valid'] = explode(' ', $data['valid']); } // Convert abbreviated encodings to full name. foreach ($data['valid'] as &$short) { $found = array_search($short, $encoding_mappings); if ($found !== false) { $short = $found; } } unset($short); // Remove reference. // Check validity. foreach ($encodings as $encoding) { $valid = mb_check_encoding($data['string'], $encoding); $expected = array_search($encoding, $data['valid']) !== false; if ($valid != $expected) { printf("\"%s\" should be %s in %s, but is detected as %s\n", $name, $expected ? 'valid' : 'invalid', $encoding, $valid ? 'valid' : 'invalid' ); } } }

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.0150.00018.40
8.3.50.0130.00522.01
8.3.40.0070.01018.84
8.3.30.0110.00419.04
8.3.20.0000.00720.33
8.3.10.0050.00323.84
8.3.00.0040.00419.02
8.2.180.0090.00616.63
8.2.170.0110.00322.96
8.2.160.0070.00720.60
8.2.150.0000.00824.18
8.2.140.0090.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00020.97
8.2.110.0000.00922.37
8.2.100.0040.00722.25
8.2.90.0000.00919.36
8.2.80.0060.00317.97
8.2.70.0060.00317.63
8.2.60.0040.00418.18
8.2.50.0040.00418.07
8.2.40.0030.00521.08
8.2.30.0020.00518.39
8.2.20.0030.00518.12
8.2.10.0000.00718.38
8.2.00.0000.00818.09
8.1.280.0140.00725.92
8.1.270.0080.00024.04
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0000.00922.32
8.1.230.0070.00419.35
8.1.220.0030.00617.89
8.1.210.0080.00018.77
8.1.200.0060.00617.60
8.1.190.0040.00417.61
8.1.180.0080.00018.10
8.1.170.0060.00318.77
8.1.160.0100.00022.27
8.1.150.0040.00418.76
8.1.140.0040.00417.72
8.1.130.0020.00517.88
8.1.120.0040.00417.62
8.1.110.0050.00217.68
8.1.100.0000.00717.63
8.1.90.0070.00417.67
8.1.80.0030.00517.63
8.1.70.0060.00317.55
8.1.60.0030.00517.80
8.1.50.0000.00817.78
8.1.40.0030.00617.66
8.1.30.0030.00517.76
8.1.20.0000.00817.69
8.1.10.0040.00417.82
8.1.00.0080.00017.78
8.0.300.0040.00418.77
8.0.290.0040.00416.72
8.0.280.0040.00418.64
8.0.270.0040.00417.33
8.0.260.0000.00717.45
8.0.250.0030.00317.00
8.0.240.0040.00417.00
8.0.230.0050.00317.13
8.0.220.0070.00016.99
8.0.210.0000.00717.08
8.0.200.0050.00317.02
8.0.190.0080.00016.99
8.0.180.0000.00717.12
8.0.170.0040.00417.08
8.0.160.0040.00417.10
8.0.150.0000.00816.91
8.0.140.0000.00717.00
8.0.130.0060.00013.53
8.0.120.0040.00417.04
8.0.110.0040.00416.95
8.0.100.0050.00216.87
8.0.90.0040.00416.87
8.0.80.0070.01517.07
8.0.70.0030.00517.00
8.0.60.0000.00816.89
8.0.50.0040.00417.10
8.0.30.0120.01117.17
8.0.20.0060.01617.40
8.0.10.0050.00217.12
8.0.00.0100.00716.77
7.4.330.0000.00515.00
7.4.320.0070.00016.67
7.4.300.0000.00616.73
7.4.290.0070.00016.79
7.4.280.0000.00716.64
7.4.270.0060.00316.74
7.4.260.0000.01016.63
7.4.250.0040.00416.69
7.4.240.0040.00416.73
7.4.230.0030.00316.84
7.4.220.0100.01016.52
7.4.210.0090.00616.82
7.4.200.0000.00716.40
7.4.190.0070.00016.75
7.4.160.0060.01016.81
7.4.150.0100.00717.40
7.4.140.0120.01017.86
7.4.130.0110.00616.65
7.4.120.0120.00716.66
7.4.110.0060.01016.58
7.4.100.0030.01416.71
7.4.90.0040.01716.71
7.4.80.0090.01219.39
7.4.70.0070.01016.71
7.4.60.0150.00316.48
7.4.50.0090.00016.75
7.4.40.0110.00716.73
7.4.30.0100.00716.83
7.4.00.0070.00915.04
7.3.330.0070.00013.23
7.3.320.0030.00313.32
7.3.310.0000.00816.57
7.3.300.0050.00216.39
7.3.290.0150.00016.45
7.3.280.0090.00816.47
7.3.270.0070.01017.40
7.3.260.0140.00316.45
7.3.250.0090.00816.62
7.3.240.0120.01316.59
7.3.230.0130.01016.72
7.3.210.0160.01316.81
7.3.200.0160.00719.39
7.3.190.0060.00916.70
7.3.180.0120.00416.58
7.3.170.0090.00616.57
7.3.160.0070.01016.45
7.3.120.0030.01215.03
7.3.110.0060.00615.02
7.3.100.0100.00714.96
7.3.90.0040.01214.66
7.3.80.0060.00615.10
7.3.70.0080.00814.91
7.3.60.0030.01314.86
7.3.50.0000.00914.94
7.3.40.0090.00014.98
7.3.30.0100.00314.82
7.3.20.0090.00616.90
7.3.10.0030.00716.88
7.3.00.0060.00316.86
7.2.330.0170.00716.73
7.2.320.0120.00916.48
7.2.310.0030.01316.61
7.2.300.0150.00316.71
7.2.290.0180.00016.98
7.2.250.0100.01015.05
7.2.240.0040.01115.07
7.2.230.0070.00714.94
7.2.220.0000.01015.31
7.2.210.0070.00715.07
7.2.200.0140.00415.05
7.2.190.0100.00715.10
7.2.180.0130.00015.13
7.2.170.0040.01115.24
7.2.160.0040.00815.06
7.2.150.0030.00717.21
7.2.140.0030.01016.90
7.2.130.0030.00617.07
7.2.120.0040.00816.81
7.2.110.0040.01117.03
7.2.100.0090.00617.07
7.2.90.0000.01017.21
7.2.80.0030.01017.11
7.2.70.0100.00616.79
7.2.60.0090.00717.00
7.2.50.0030.01017.14
7.2.40.0080.00517.17
7.2.30.0070.00716.98
7.2.20.0030.00617.18
7.2.10.0070.00717.13
7.2.00.0000.01318.34
7.1.330.0000.01515.91
7.1.320.0000.01116.10
7.1.310.0060.00616.07
7.1.300.0070.00715.99
7.1.290.0080.00316.02
7.1.280.0000.01215.75
7.1.270.0060.00816.02
7.1.260.0070.00715.80
7.1.250.0080.00815.70
7.1.240.0050.00515.96
7.1.230.0000.00916.02
7.1.220.0040.00815.80
7.1.210.0070.00415.93
7.1.200.0020.01115.79
7.1.190.0070.01015.86
7.1.180.0040.00416.05
7.1.170.0090.00315.89
7.1.160.0070.00715.78
7.1.150.0160.00015.78
7.1.140.0040.01115.90
7.1.130.0030.00616.05
7.1.120.0030.00716.22
7.1.110.0060.00616.00
7.1.100.0020.01017.28
7.1.90.0000.01316.05
7.1.80.0030.01015.77
7.1.70.0040.00616.56
7.1.60.0090.00817.82
7.1.50.0050.01316.41
7.1.40.0130.00015.98
7.1.30.0100.00616.08
7.1.20.0070.01015.97
7.1.10.0060.00616.19
7.1.00.0070.03919.27
7.0.330.0090.00315.56
7.0.320.0000.01015.64
7.0.310.0140.00015.41
7.0.300.0120.00415.54
7.0.290.0070.01015.33
7.0.280.0040.01415.66
7.0.270.0050.00515.37
7.0.260.0000.01115.60
7.0.250.0040.00815.27
7.0.240.0000.01115.76
7.0.230.0030.01015.76
7.0.220.0040.00715.78
7.0.210.0090.00015.70
7.0.200.0040.00716.41
7.0.190.0030.00915.76
7.0.180.0040.00715.66
7.0.170.0100.00715.73
7.0.160.0070.00315.62
7.0.150.0040.00715.23
7.0.140.0040.04418.84
7.0.130.0040.01115.33
7.0.120.0060.00915.66
7.0.110.0190.02517.70
7.0.100.0200.02517.84
7.0.90.0240.02717.82
7.0.80.0160.03517.82
7.0.70.0170.03017.74
7.0.60.0110.02017.83
7.0.50.0080.02918.02
7.0.40.0080.02116.93
7.0.30.0020.02716.87
7.0.20.0020.03016.89
7.0.10.0070.02516.82
7.0.00.0060.02416.86
5.6.400.0000.01314.44
5.6.390.0070.00614.85
5.6.380.0070.00714.87
5.6.370.0040.00714.74
5.6.360.0000.01414.64
5.6.350.0030.01214.44
5.6.340.0070.00714.43
5.6.330.0080.00314.53
5.6.320.0090.00314.82
5.6.310.0040.01214.81
5.6.300.0070.00714.87
5.6.290.0070.01114.86
5.6.280.0070.03817.78
5.6.270.0060.00314.64
5.6.260.0070.02317.49
5.6.250.0050.02417.73
5.6.240.0020.02717.63
5.6.230.0030.03317.66
5.6.220.0040.02617.55
5.6.210.0030.02517.61
5.6.200.0030.03017.69
5.6.190.0070.02417.85
5.6.180.0130.01817.85
5.6.170.0050.03018.01
5.6.160.0070.03517.83
5.6.150.0080.03317.86
5.6.140.0070.02217.86
5.6.130.0040.02718.10
5.6.120.0050.02317.80
5.6.110.0050.03117.68
5.6.100.0080.03817.79
5.6.90.0120.02717.84
5.6.80.0000.04417.48
5.6.70.0050.04417.58
5.6.60.0090.03717.58
5.6.50.0030.04417.57
5.6.40.0130.03517.54
5.6.30.0070.04417.61
5.6.20.0150.03517.50
5.6.10.0020.05017.47
5.6.00.0050.04417.55
5.5.380.0070.02017.51
5.5.370.0000.04717.67
5.5.360.0060.02317.61
5.5.350.0050.02317.45
5.5.340.0030.02617.73
5.5.330.0020.02717.79
5.5.320.0050.02617.78
5.5.310.0000.02717.71
5.5.300.0050.02117.78
5.5.290.0020.02717.62
5.5.280.0020.03917.73
5.5.270.0060.02617.75
5.5.260.0050.04717.48
5.5.250.0040.04517.35
5.5.240.0030.04517.36
5.5.230.0080.04217.36
5.5.220.0050.04517.30
5.5.210.0050.04117.44
5.5.200.0020.05017.18
5.5.190.0040.04717.45
5.5.180.0120.02517.40
5.5.170.0030.01014.52
5.5.160.0030.04417.36
5.5.150.0080.04217.39
5.5.140.0100.03617.37
5.5.130.0100.04517.25
5.5.120.0080.04017.45
5.5.110.0060.03817.43
5.5.100.0060.04117.11
5.5.90.0060.03817.29
5.5.80.0100.04017.44
5.5.70.0070.04017.07
5.5.60.0020.04417.27
5.5.50.0120.03717.44
5.5.40.0070.04017.31
5.5.30.0090.03017.30
5.5.20.0150.03517.32
5.5.10.0080.04017.30
5.5.00.0070.04217.33
5.4.450.0030.02215.40
5.4.440.0060.02115.35
5.4.430.0050.02215.34
5.4.420.0040.02115.38
5.4.410.0000.04515.38
5.4.400.0050.04015.21
5.4.390.0090.03915.18
5.4.380.0030.04215.08
5.4.370.0050.02715.16
5.4.360.0060.03115.16
5.4.350.0030.04315.12
5.4.340.0090.03515.16
5.4.330.0040.00811.20
5.4.320.0050.04415.18
5.4.310.0050.04215.10
5.4.300.0070.04415.10
5.4.290.0050.02515.18
5.4.280.0100.03815.12
5.4.270.0060.04115.12
5.4.260.0090.04215.05
5.4.250.0030.04315.07
5.4.240.0080.03815.19
5.4.230.0120.02015.08
5.4.220.0050.04515.25
5.4.210.0070.03915.20
5.4.200.0110.03815.11
5.4.190.0100.03815.16
5.4.180.0030.04215.22
5.4.170.0060.04315.07
5.4.160.0060.03815.23
5.4.150.0030.04415.12
5.4.140.0070.03413.74
5.4.130.0030.04113.93
5.4.120.0070.03713.83
5.4.110.0110.03513.84
5.4.100.0120.03213.78
5.4.90.0060.03613.85
5.4.80.0080.03613.81
5.4.70.0030.04413.78
5.4.60.0030.03813.96
5.4.50.0050.04213.85
5.4.40.0110.02213.81
5.4.30.0030.03913.80
5.4.20.0050.04213.76
5.4.10.0060.02313.87
5.4.00.0070.03513.46
5.3.290.0090.03212.99
5.3.280.0050.02912.95
5.3.270.0050.03612.88
5.3.260.0020.02712.93
5.3.250.0070.03212.82
5.3.240.0020.04312.92
5.3.230.0070.04212.81
5.3.220.0050.04012.91
5.3.210.0060.04212.83
5.3.200.0050.04112.85
5.3.190.0030.04312.91
5.3.180.0080.03512.83
5.3.170.0080.03612.84
5.3.160.0050.04412.88
5.3.150.0080.03712.80
5.3.140.0050.02712.87
5.3.130.0100.03812.86
5.3.120.0060.04112.91
5.3.110.0000.03212.84
5.3.100.0050.04212.57
5.3.90.0080.03712.60
5.3.80.0080.03312.59
5.3.70.0020.03512.58
5.3.60.0030.02612.59
5.3.50.0000.02912.52
5.3.40.0070.03212.51
5.3.30.0090.03512.51
5.3.20.0050.04112.40
5.3.10.0030.03012.38
5.3.00.0020.04012.41
5.2.170.0130.05312.14
5.2.160.0030.06712.14
5.2.150.0070.06312.14
5.2.140.0030.05312.14
5.2.130.0070.05712.14
5.2.120.0030.04712.14
5.2.110.0070.05712.14
5.2.100.0070.06012.14
5.2.90.0000.06712.14
5.2.80.0100.05012.14
5.2.70.0030.06012.14
5.2.60.0030.06012.14
5.2.50.0100.05012.14
5.2.40.0070.06012.14
5.2.30.0070.05712.14
5.2.20.0170.05012.14
5.2.10.0000.06712.14
5.2.00.0100.05312.14
5.1.60.0070.04312.14
5.1.50.0030.05312.14
5.1.40.0030.05012.14
5.1.30.0070.05012.14
5.1.20.0070.05312.14
5.1.10.0100.05012.14
5.1.00.0070.05312.14
5.0.50.0070.04312.14
5.0.40.0070.03712.14
5.0.30.0030.06012.14
5.0.20.0100.03012.14
5.0.10.0030.04012.14
5.0.00.0070.05712.14
4.4.90.0030.03312.14
4.4.80.0000.03712.14
4.4.70.0030.03712.14
4.4.60.0100.03012.14
4.4.50.0070.02712.14
4.4.40.0000.05712.14
4.4.30.0000.03712.14
4.4.20.0070.03012.14
4.4.10.0070.03012.14
4.4.00.0030.05312.14
4.3.110.0030.03012.14
4.3.100.0000.03712.14
4.3.90.0100.02712.14
4.3.80.0100.04712.14
4.3.70.0030.03312.14
4.3.60.0030.03312.14
4.3.50.0030.01712.14
4.3.40.0030.04012.14
4.3.30.0070.03012.14
4.3.20.0030.03012.14
4.3.10.0000.04012.14
4.3.00.0030.03312.14

preferences:
42.38 ms | 401 KiB | 5 Q