3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $examples = array( 'Valid ASCII' => "a", 'Valid 2 Octet Sequence' => "\xc3\xb1", 'Invalid 2 Octet Sequence' => "\xc3\x28", 'Invalid Sequence Identifier' => "\xa0\xa1", 'Valid 3 Octet Sequence' => "\xe2\x82\xa1", 'Invalid 3 Octet Sequence (in 2nd Octet)' => "\xe2\x28\xa1", 'Invalid 3 Octet Sequence (in 3rd Octet)' => "\xe2\x82\x28", 'Valid 4 Octet Sequence' => "\xf0\x90\x8c\xbc", 'Invalid 4 Octet Sequence (in 2nd Octet)' => "\xf0\x28\x8c\xbc", 'Invalid 4 Octet Sequence (in 3rd Octet)' => "\xf0\x90\x28\xbc", 'Invalid 4 Octet Sequence (in 4th Octet)' => "\xf0\x28\x8c\x28", 'Valid 5 Octet Sequence (but not Unicode!)' => "\xf8\xa1\xa1\xa1\xa1", 'Valid 6 Octet Sequence (but not Unicode!)' => "\xfc\xa1\xa1\xa1\xa1\xa1", ); echo "++Invalid UTF-8 in pattern\n"; foreach ( $examples as $name => $str ) { echo "$name\n"; preg_match("/".$str."/u",'Testing'); } echo "++ preg_match() examples\n"; foreach ( $examples as $name => $str ) { preg_match("/\xf8\xa1\xa1\xa1\xa1/u", $str, $ar); echo "$name: "; if ( count($ar) == 0 ) { echo "Matched nothing!\n"; } else { echo "Matched {$ar[0]}\n"; } } echo "++ preg_match_all() examples\n"; foreach ( $examples as $name => $str ) { preg_match_all('/./u', $str, $ar); echo "$name: "; $num_utf8_chars = count($ar[0]); if ( $num_utf8_chars == 0 ) { echo "Matched nothing!\n"; } else { echo "Matched $num_utf8_chars character\n"; } }
Output for 5.3.19 - 5.3.29, 5.4.9 - 7.1.0
++Invalid UTF-8 in pattern Valid ASCII Valid 2 Octet Sequence Invalid 2 Octet Sequence Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Invalid Sequence Identifier Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 3 Octet Sequence Invalid 3 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Invalid 3 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 4 Octet Sequence Invalid 4 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 4th Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 5 Octet Sequence (but not Unicode!) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 6 Octet Sequence (but not Unicode!) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 ++ preg_match() examples Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid ASCII: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 2 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 2 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid Sequence Identifier: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 3 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 4 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 5 Octet Sequence (but not Unicode!): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 6 Octet Sequence (but not Unicode!): Matched nothing! ++ preg_match_all() examples Valid ASCII: Matched 1 character Valid 2 Octet Sequence: Matched 1 character Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched 1 character Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched 1 character Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched nothing! Valid 6 Octet Sequence (but not Unicode!): Matched nothing!
Output for 4.4.9, 5.2.5 - 5.3.18, 5.4.0 - 5.4.8
++Invalid UTF-8 in pattern Valid ASCII Valid 2 Octet Sequence Invalid 2 Octet Sequence Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid Sequence Identifier Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 3 Octet Sequence Invalid 3 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 3 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Valid 4 Octet Sequence Invalid 4 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 4th Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Valid 5 Octet Sequence (but not Unicode!) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 6 Octet Sequence (but not Unicode!) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 ++ preg_match() examples Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid ASCII: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 2 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 2 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid Sequence Identifier: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 3 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 4 Octet Sequence: Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 5 Octet Sequence (but not Unicode!): Matched nothing! Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 28 Valid 6 Octet Sequence (but not Unicode!): Matched nothing! ++ preg_match_all() examples Valid ASCII: Matched 1 character Valid 2 Octet Sequence: Matched 1 character Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched 1 character Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched 1 character Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched nothing! Valid 6 Octet Sequence (but not Unicode!): Matched nothing!
Output for 4.3.11 - 4.4.8, 5.0.0 - 5.2.4
++Invalid UTF-8 in pattern Valid ASCII Valid 2 Octet Sequence Invalid 2 Octet Sequence Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid Sequence Identifier Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 3 Octet Sequence Invalid 3 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 3 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Valid 4 Octet Sequence Invalid 4 Octet Sequence (in 2nd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 3rd Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 4th Octet) Warning: preg_match(): Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Valid 5 Octet Sequence (but not Unicode!) Valid 6 Octet Sequence (but not Unicode!) ++ preg_match() examples Valid ASCII: Matched nothing! Valid 2 Octet Sequence: Matched nothing! Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched nothing! Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched nothing! Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched ����� Valid 6 Octet Sequence (but not Unicode!): Matched nothing! ++ preg_match_all() examples Valid ASCII: Matched 1 character Valid 2 Octet Sequence: Matched 1 character Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched 1 character Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched 1 character Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched 1 character Valid 6 Octet Sequence (but not Unicode!): Matched 1 character
Output for 4.3.5 - 4.3.10
++Invalid UTF-8 in pattern Valid ASCII Valid 2 Octet Sequence Invalid 2 Octet Sequence Warning: Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid Sequence Identifier Warning: Compilation failed: invalid UTF-8 string at offset 0 in /in/T1vk1 on line 22 Valid 3 Octet Sequence Invalid 3 Octet Sequence (in 2nd Octet) Warning: Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 3 Octet Sequence (in 3rd Octet) Warning: Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Valid 4 Octet Sequence Invalid 4 Octet Sequence (in 2nd Octet) Warning: Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 3rd Octet) Warning: Compilation failed: invalid UTF-8 string at offset 2 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 4th Octet) Warning: Compilation failed: invalid UTF-8 string at offset 1 in /in/T1vk1 on line 22 Valid 5 Octet Sequence (but not Unicode!) Valid 6 Octet Sequence (but not Unicode!) ++ preg_match() examples Valid ASCII: Matched nothing! Valid 2 Octet Sequence: Matched nothing! Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched nothing! Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched nothing! Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched ����� Valid 6 Octet Sequence (but not Unicode!): Matched nothing! ++ preg_match_all() examples Valid ASCII: Matched 1 character Valid 2 Octet Sequence: Matched 1 character Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched 1 character Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched 1 character Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched 1 character Valid 6 Octet Sequence (but not Unicode!): Matched 1 character
Output for 4.3.0 - 4.3.4
++Invalid UTF-8 in pattern Valid ASCII Valid 2 Octet Sequence Invalid 2 Octet Sequence Warning: Compilation failed: missing ) at offset 2 in /in/T1vk1 on line 22 Invalid Sequence Identifier Valid 3 Octet Sequence Invalid 3 Octet Sequence (in 2nd Octet) Warning: Compilation failed: missing ) at offset 3 in /in/T1vk1 on line 22 Invalid 3 Octet Sequence (in 3rd Octet) Warning: Compilation failed: missing ) at offset 3 in /in/T1vk1 on line 22 Valid 4 Octet Sequence Invalid 4 Octet Sequence (in 2nd Octet) Warning: Compilation failed: missing ) at offset 4 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 3rd Octet) Warning: Compilation failed: missing ) at offset 4 in /in/T1vk1 on line 22 Invalid 4 Octet Sequence (in 4th Octet) Warning: Compilation failed: missing ) at offset 4 in /in/T1vk1 on line 22 Valid 5 Octet Sequence (but not Unicode!) Valid 6 Octet Sequence (but not Unicode!) ++ preg_match() examples Valid ASCII: Matched nothing! Valid 2 Octet Sequence: Matched nothing! Invalid 2 Octet Sequence: Matched nothing! Invalid Sequence Identifier: Matched nothing! Valid 3 Octet Sequence: Matched nothing! Invalid 3 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 3 Octet Sequence (in 3rd Octet): Matched nothing! Valid 4 Octet Sequence: Matched nothing! Invalid 4 Octet Sequence (in 2nd Octet): Matched nothing! Invalid 4 Octet Sequence (in 3rd Octet): Matched nothing! Invalid 4 Octet Sequence (in 4th Octet): Matched nothing! Valid 5 Octet Sequence (but not Unicode!): Matched ����� Valid 6 Octet Sequence (but not Unicode!): Matched nothing! ++ preg_match_all() examples Valid ASCII: Matched 1 character Valid 2 Octet Sequence: Matched 1 character Invalid 2 Octet Sequence: Matched 2 character Invalid Sequence Identifier: Matched 1 character Valid 3 Octet Sequence: Matched 1 character Invalid 3 Octet Sequence (in 2nd Octet): Matched 2 character Invalid 3 Octet Sequence (in 3rd Octet): Matched 2 character Valid 4 Octet Sequence: Matched 1 character Invalid 4 Octet Sequence (in 2nd Octet): Matched 2 character Invalid 4 Octet Sequence (in 3rd Octet): Matched 2 character Invalid 4 Octet Sequence (in 4th Octet): Matched 3 character Valid 5 Octet Sequence (but not Unicode!): Matched 1 character Valid 6 Octet Sequence (but not Unicode!): Matched 1 character