mb_ereg_variation3.phpt 3.0 KB

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