mb_stripos_basic.phpt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. --TEST--
  2. Test mb_stripos() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
  11. * Description: Finds position of first occurrence of a string within another, case insensitive
  12. * Source code: ext/mbstring/mbstring.c
  13. * Alias to functions:
  14. */
  15. /*
  16. * Test basic functionality of mb_stripos with ASCII and multibyte characters
  17. */
  18. echo "*** Testing mb_stripos() : basic functionality***\n";
  19. mb_internal_encoding('UTF-8');
  20. //ascii strings
  21. $ascii_haystacks = array(
  22. b'abc defabc def',
  23. b'ABC DEFABC DEF',
  24. b'Abc dEFaBC Def',
  25. );
  26. $ascii_needles = array(
  27. // 4 good ones
  28. b'DE',
  29. b'de',
  30. b'De',
  31. b'dE',
  32. //flag a swap between good and bad
  33. '!',
  34. // 4 bad ones
  35. b'df',
  36. b'Df',
  37. b'dF',
  38. b'DF'
  39. );
  40. //greek strings in UTF-8
  41. $greek_lower = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
  42. $greek_upper = base64_decode('zpHOks6TzpTOlc6WzpfOmM6ZzprOm86czp3Ons6fzqDOoc6jzqTOpc6mzqfOqM6p');
  43. $greek_mixed = base64_decode('zrHOss6TzpTOlc6WzpfOmM65zrrOu868zr3Ovs6fzqDOoc6jzqTOpc+Gz4fPiM+J');
  44. $greek_haystacks = array($greek_lower, $greek_upper, $greek_mixed);
  45. $greek_nlower = base64_decode('zrzOvc6+zr8=');
  46. $greek_nupper = base64_decode('zpzOnc6ezp8=');
  47. $greek_nmixed1 = base64_decode('zpzOnc6+zr8=');
  48. $greek_nmixed2 = base64_decode('zrzOvc6+zp8=');
  49. $greek_blower = base64_decode('zpzOns6f');
  50. $greek_bupper = base64_decode('zrzOvs6/');
  51. $greek_bmixed1 = base64_decode('zpzOvs6/');
  52. $greek_bmixed2 = base64_decode('zrzOvs6f');
  53. $greek_needles = array(
  54. // 4 good ones
  55. $greek_nlower, $greek_nupper, $greek_nmixed1, $greek_nmixed2,
  56. '!', // used to flag a swap between good and bad
  57. // 4 bad ones
  58. $greek_blower, $greek_bupper, $greek_bmixed1, $greek_bmixed2,
  59. );
  60. // try the basic options
  61. echo "\n -- ASCII Strings, needle should be found --\n";
  62. foreach ($ascii_needles as $needle) {
  63. if ($needle == '!') {
  64. echo "\n -- ASCII Strings, needle should not be found --\n";
  65. }
  66. else {
  67. foreach ($ascii_haystacks as $haystack) {
  68. var_dump(mb_stripos($haystack, $needle));
  69. }
  70. }
  71. }
  72. echo "\n -- Greek Strings, needle should be found --\n";
  73. foreach ($greek_needles as $needle) {
  74. if ($needle == '!') {
  75. echo "\n -- ASCII Strings, needle should not be found --\n";
  76. }
  77. else {
  78. foreach ($greek_haystacks as $haystack) {
  79. var_dump(mb_stripos($haystack, $needle));
  80. }
  81. }
  82. }
  83. echo "Done";
  84. ?>
  85. --EXPECTF--
  86. *** Testing mb_stripos() : basic functionality***
  87. -- ASCII Strings, needle should be found --
  88. int(4)
  89. int(4)
  90. int(4)
  91. int(4)
  92. int(4)
  93. int(4)
  94. int(4)
  95. int(4)
  96. int(4)
  97. int(4)
  98. int(4)
  99. int(4)
  100. -- ASCII Strings, needle should not be found --
  101. bool(false)
  102. bool(false)
  103. bool(false)
  104. bool(false)
  105. bool(false)
  106. bool(false)
  107. bool(false)
  108. bool(false)
  109. bool(false)
  110. bool(false)
  111. bool(false)
  112. bool(false)
  113. -- Greek Strings, needle should be found --
  114. int(11)
  115. int(11)
  116. int(11)
  117. int(11)
  118. int(11)
  119. int(11)
  120. int(11)
  121. int(11)
  122. int(11)
  123. int(11)
  124. int(11)
  125. int(11)
  126. -- ASCII Strings, needle should not be found --
  127. bool(false)
  128. bool(false)
  129. bool(false)
  130. bool(false)
  131. bool(false)
  132. bool(false)
  133. bool(false)
  134. bool(false)
  135. bool(false)
  136. bool(false)
  137. bool(false)
  138. bool(false)
  139. Done