mb_ereg_variation3.phpt 3.0 KB

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