xref: /PHP-8.0/ext/mbstring/tests/mb_ereg.phpt (revision 5582490b)
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( ' ', $reg ), $in_enc, $test_enc )) : '' ) );
21    }
22    function do_tests( $enc ) {
23        test_ereg( $enc, 'abc ([a-z]+) ([a-z]+) ([a-z]+)$', "abc def ghi jkl" );
24        $pat = '([��-��]+) ([ ��-��]+)([��-��]+) ([��-��]+)$';
25        test_ereg( $enc, $pat, '���� ������ ������ ����' );
26        test_ereg( $enc, $pat, '�������� ������ ���� ���' );
27    }
28
29    foreach( $encs as $enc ) {
30        do_tests( $enc );
31    }
32?>
33--EXPECT--
34(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
35(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
36(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
37(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
38(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
39(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
40(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
41(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
42(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
43(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
44(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
45(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
46