xref: /PHP-5.6/ext/mbstring/tests/mb_ereg.phpt (revision 4a78652f)
1--TEST--
2mb_ereg()
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip mbstring not available');
6function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
7?>
8--INI--
9output_handler=
10--FILE--
11<?php
12	mb_regex_set_options( '' );
13
14	$encs = array( 'EUC-JP', 'Shift_JIS', 'SJIS', 'UTF-8' );
15
16	function test_ereg( $test_enc, $pat, $str, $in_enc = 'EUC-JP' ) {
17		mb_regex_encoding( $test_enc );
18		$pat = mb_convert_encoding( $pat, $test_enc, $in_enc );
19		$str = mb_convert_encoding( $str, $test_enc, $in_enc );
20		printf( "(%d)%s\n", mb_ereg( $pat, $str, $reg ), ( is_array( $reg )? bin2hex(mb_convert_encoding( implode( b' ', $reg ), $in_enc, $test_enc )) : '' ) );
21	}
22	function do_tests( $enc ) {
23		test_ereg( $enc, b'abc ([a-z]+) ([a-z]+) ([a-z]+)$', b"abc def ghi jkl" );
24		$pat = b'([��-��]+) ([ ��-��]+)([��-��]+) ([��-��]+)$';
25		test_ereg( $enc, $pat, b'���� ������ ������ ����' );
26		test_ereg( $enc, $pat, b'�������� ������ ���� ���' );
27	}
28
29	foreach( $encs as $enc ) {
30		do_tests( $enc );
31	}
32?>
33
34--EXPECT--
35(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
36(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
37(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
38(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
39(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
40(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
41(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
42(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
43(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
44(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
45(39)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
46(39)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0