mb_strripos_basic.phpt 2.9 KB

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