1--TEST--
2Test mb_ereg_replace() function : basic
3--EXTENSIONS--
4mbstring
5--SKIPIF--
6<?php
7function_exists('mb_ereg_replace') or die("skip mb_ereg_replace() is not available in this build");
8?>
9--FILE--
10<?php
11/*
12 * Test Basic Functionality of mb_ereg_replace()
13 */
14
15echo "*** Testing mb_ereg_replace() : basic functionality ***\n";
16
17mb_internal_encoding('UTF-8');
18mb_regex_encoding('UTF-8');
19
20$string_ascii = 'abc def';
21$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
22
23echo "\n-- ASCII string 1 --\n";
24$result_1 = mb_ereg_replace('(.*)def', '\\1 123', $string_ascii);
25var_dump(bin2hex($result_1));
26
27echo "\n-- ASCII string 2 --\n";
28$result_2 = mb_ereg_replace('123', 'abc', $string_ascii);
29var_dump(bin2hex($result_2));
30
31echo "\n-- Multibyte string 1 --\n";
32$regex1 = base64_decode('KOaXpeacrOiqnikuKj8oWzEtOV0rKQ==');   //Japanese regex in UTF-8
33$result_3 = mb_ereg_replace($regex1, '\\1_____\\2', $string_mb);
34var_dump(bin2hex($result_3));
35
36echo "\n-- Multibyte string 2 --\n";
37$regex2 = base64_decode('5LiW55WM');
38$result_4 = mb_ereg_replace($regex2, '_____', $string_mb);
39var_dump(bin2hex($result_4));
40
41echo "Done";
42?>
43--EXPECT--
44*** Testing mb_ereg_replace() : basic functionality ***
45
46-- ASCII string 1 --
47string(16) "6162632020313233"
48
49-- ASCII string 2 --
50string(14) "61626320646566"
51
52-- Multibyte string 1 --
53string(72) "e697a5e69cace8aa9e5f5f5f5f5f31323334efbc95efbc96efbc97efbc98efbc99e38082"
54
55-- Multibyte string 2 --
56string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
57Done
58