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