Annotation of embedaddon/php/ext/mbstring/tests/mb_ereg_variation3.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mb_ereg() function : usage variations - pass different character classes to see they match correctly
! 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 that mb_ereg can match correctly when passed different character classes.
! 17: */
! 18:
! 19: echo "*** Testing mb_ereg() : variation ***\n";
! 20:
! 21:
! 22: mb_regex_encoding('utf-8'); // have to set otherwise won't match $mb properly
! 23: $mb = base64_decode('5pel5pys6Kqe');
! 24: $character_classes = array (b'aB1' => b'[[:alnum:]]+', /*1*/
! 25: b'aBcD' => b'[[:alpha:]]+',
! 26: b'ab/=' => b'[[:ascii:]]+',
! 27: b" \t" => b'[[:blank:]]+',
! 28: b'234' => b'[[:digit:]]+', /*5*/
! 29: "$mb" => b'[[:graph:]]+',
! 30: b'fjds' => b'[[:lower:]]+',
! 31: b"$mb\t" => b'[[:print:]]+',
! 32: b'.!"*@' => b'[[:punct:]]+',
! 33: b"\t" => b'[[:space:]]+', /*10*/
! 34: b'IDSJV' => b'[[:upper:]]+',
! 35: b'3b5D' => b'[[:xdigit:]]+'); /*12*/
! 36:
! 37: $iterator = 1;
! 38: foreach($character_classes as $string => $pattern) {
! 39: if (is_array(@$regs)) {
! 40: $regs = null;
! 41: }
! 42: // make sure any multibyte output is in base 64
! 43: echo "\n-- Iteration $iterator --\n";
! 44: var_dump(mb_ereg($pattern, $string, $regs));
! 45: base64_encode_var_dump($regs);
! 46: $iterator++;
! 47: }
! 48: /**
! 49: * replicate a var dump of an array but outputted string values are base64 encoded
! 50: *
! 51: * @param array $regs
! 52: */
! 53: function base64_encode_var_dump($regs) {
! 54: if ($regs) {
! 55: echo "array(" . count($regs) . ") {\n";
! 56: foreach ($regs as $key => $value) {
! 57: echo " [$key]=>\n ";
! 58: if (is_string($value)) {
! 59: var_dump(base64_encode($value));
! 60: } else {
! 61: var_dump($value);
! 62: }
! 63: }
! 64: echo "}\n";
! 65: } else {
! 66: echo "NULL\n";
! 67: }
! 68: }
! 69:
! 70: echo "Done";
! 71: ?>
! 72:
! 73: --EXPECT--
! 74: *** Testing mb_ereg() : variation ***
! 75:
! 76: -- Iteration 1 --
! 77: int(3)
! 78: array(1) {
! 79: [0]=>
! 80: string(4) "YUIx"
! 81: }
! 82:
! 83: -- Iteration 2 --
! 84: int(4)
! 85: array(1) {
! 86: [0]=>
! 87: string(8) "YUJjRA=="
! 88: }
! 89:
! 90: -- Iteration 3 --
! 91: int(4)
! 92: array(1) {
! 93: [0]=>
! 94: string(8) "YWIvPQ=="
! 95: }
! 96:
! 97: -- Iteration 4 --
! 98: int(2)
! 99: array(1) {
! 100: [0]=>
! 101: string(4) "IAk="
! 102: }
! 103:
! 104: -- Iteration 5 --
! 105: int(3)
! 106: array(1) {
! 107: [0]=>
! 108: string(4) "MjM0"
! 109: }
! 110:
! 111: -- Iteration 6 --
! 112: int(9)
! 113: array(1) {
! 114: [0]=>
! 115: string(12) "5pel5pys6Kqe"
! 116: }
! 117:
! 118: -- Iteration 7 --
! 119: int(4)
! 120: array(1) {
! 121: [0]=>
! 122: string(8) "Zmpkcw=="
! 123: }
! 124:
! 125: -- Iteration 8 --
! 126: int(10)
! 127: array(1) {
! 128: [0]=>
! 129: string(16) "5pel5pys6KqeCQ=="
! 130: }
! 131:
! 132: -- Iteration 9 --
! 133: int(5)
! 134: array(1) {
! 135: [0]=>
! 136: string(8) "LiEiKkA="
! 137: }
! 138:
! 139: -- Iteration 10 --
! 140: int(1)
! 141: array(1) {
! 142: [0]=>
! 143: string(4) "CQ=="
! 144: }
! 145:
! 146: -- Iteration 11 --
! 147: int(5)
! 148: array(1) {
! 149: [0]=>
! 150: string(8) "SURTSlY="
! 151: }
! 152:
! 153: -- Iteration 12 --
! 154: int(4)
! 155: array(1) {
! 156: [0]=>
! 157: string(8) "M2I1RA=="
! 158: }
! 159: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>