Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_variation5.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mb_ereg() function : usage variations - Test anchors in regex
! 3: --SKIPIF--
! 4: <?php
! 5: extension_loaded('mbstring') or die('skip');
! 6: function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build");
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : int mb_ereg(string $pattern, string $string [, array $registers])
! 11: * Description: Regular expression match for multibyte string
! 12: * Source code: ext/mbstring/php_mbregex.c
! 13: */
! 14:
! 15: /*
! 16: * Test mb_ereg with anchors (start and end of string) in $pattern
! 17: */
! 18:
! 19: echo "*** Testing mb_ereg() : usage variations ***\n";
! 20:
! 21: mb_regex_encoding('utf-8');
! 22:
! 23: $string_ascii = b'This is an English string. 0123456789.';
! 24: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
! 25:
! 26: $regex = b'^.*?[[:blank:]]?[[:punct:][:digit:]]+\.?$';
! 27:
! 28: echo "\nASCII String without \$regs arg:\t\t";
! 29: var_dump(mb_ereg($regex, $string_ascii));
! 30: echo "ASCII String with \$regs arg:\n";
! 31: var_dump(mb_ereg($regex, $string_ascii, $regs_ascii));
! 32: base64_encode_var_dump($regs_ascii);
! 33:
! 34: echo "\nMultibyte String without \$regs arg:\t";
! 35: var_dump(mb_ereg($regex, $string_mb));
! 36: echo "Multubyte String with \$regs arg:\n";
! 37: var_dump(mb_ereg($regex, $string_mb, $regs_mb));
! 38: base64_encode_var_dump($regs_mb);
! 39:
! 40: echo "Done";
! 41:
! 42: /**
! 43: * replicate a var dump of an array but outputted string values are base64 encoded
! 44: *
! 45: * @param array $regs
! 46: */
! 47: function base64_encode_var_dump($regs) {
! 48: if ($regs) {
! 49: echo "array(" . count($regs) . ") {\n";
! 50: foreach ($regs as $key => $value) {
! 51: echo " [$key]=>\n ";
! 52: if (is_string($value)) {
! 53: var_dump(base64_encode($value));
! 54: } else {
! 55: var_dump($value);
! 56: }
! 57: }
! 58: echo "}\n";
! 59: } else {
! 60: echo "NULL\n";
! 61: }
! 62: }
! 63: ?>
! 64: --EXPECTF--
! 65: *** Testing mb_ereg() : usage variations ***
! 66:
! 67: ASCII String without $regs arg: int(1)
! 68: ASCII String with $regs arg:
! 69: int(38)
! 70: array(1) {
! 71: [0]=>
! 72: string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4="
! 73: }
! 74:
! 75: Multibyte String without $regs arg: int(1)
! 76: Multubyte String with $regs arg:
! 77: int(53)
! 78: array(1) {
! 79: [0]=>
! 80: string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
! 81: }
! 82: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>