xref: /PHP-7.4/ext/mbstring/tests/mb_split.phpt (revision e907fbaf)
1--TEST--
2mb_split()
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip mbstring not available');
6function_exists('mb_split') or die("skip mb_split() is not available in this build");
7?>
8--INI--
9mbstring.func_overload=0
10--FILE--
11<?php
12	mb_regex_set_options( '' );
13	mb_regex_encoding( 'EUC-JP' );
14
15	function verify_split( $spliton, $str, $count = 0 )
16	{
17		$result1 = mb_split( $spliton, $str, $count );
18		$result2 = preg_split( "/$spliton/", $str, $count );
19		if ( $result1 == $result2 ) {
20			print "ok\n";
21		} else {
22			print count($result1).'-'.count($result2)."\n";
23		}
24	}
25
26	var_dump( mb_split( " ", "a b c d e f g" )
27	          == mb_split( "[[:space:]]", "a\nb\tc\nd e f g" ) );
28
29	for ( $i = 1; $i < 5; ++$i ) {
30		verify_split( " ", "a\tb\tc\td   e\tf g", $i );
31	}
32
33	for ( $i = 1; $i < 5; ++$i ) {
34		verify_split( "\xa1\xa1+", "\xa1\xa1\xa1\xa2\xa2\xa1\xa1\xa1\xa1\xa1\xa1\xa2\xa2\xa1\xa1\xa1", $i );
35	}
36?>
37--EXPECT--
38bool(true)
39ok
40ok
41ok
42ok
43ok
442-2
453-3
464-4
47