mb_stripos_basic2.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. );
  33. //greek strings in UTF-8
  34. $greek_lower = base64_decode('zrrOu868zr3Ovs6/z4DPgSDOus67zrzOvc6+zr/PgA==');
  35. $greek_upper = base64_decode('zprOm86czp3Ons6fzqDOoSDOms6bzpzOnc6ezp/OoA==');
  36. $greek_mixed = base64_decode('zrrOu868zr3Ovs6fzqDOoSDOus67zpzOnc6+zr/OoA==');
  37. $greek_haystacks = array($greek_lower, $greek_upper, $greek_mixed);
  38. $greek_nlower = base64_decode('zrzOvc6+zr8=');
  39. $greek_nupper = base64_decode('zpzOnc6ezp8=');
  40. $greek_nmixed1 = base64_decode('zpzOnc6+zr8=');
  41. $greek_nmixed2 = base64_decode('zrzOvc6+zp8=');
  42. $greek_needles = array(
  43. // 4 good ones
  44. $greek_nlower, $greek_nupper, $greek_nmixed1, $greek_nmixed2,
  45. );
  46. // try the basic options
  47. echo "\n -- ASCII Strings --\n";
  48. foreach ($ascii_needles as $needle) {
  49. foreach ($ascii_haystacks as $haystack) {
  50. var_dump(mb_stripos($haystack, $needle));
  51. var_dump(mb_stripos($haystack, $needle, 6));
  52. }
  53. }
  54. echo "\n -- Greek Strings --\n";
  55. foreach ($greek_needles as $needle) {
  56. foreach ($greek_haystacks as $haystack) {
  57. var_dump(mb_stripos($haystack, $needle));
  58. var_dump(mb_stripos($haystack, $needle, 4));
  59. }
  60. }
  61. echo "Done";
  62. ?>
  63. --EXPECTF--
  64. *** Testing mb_stripos() : basic functionality***
  65. -- ASCII Strings --
  66. int(4)
  67. int(13)
  68. int(4)
  69. int(13)
  70. int(4)
  71. int(13)
  72. int(4)
  73. int(13)
  74. int(4)
  75. int(13)
  76. int(4)
  77. int(13)
  78. int(4)
  79. int(13)
  80. int(4)
  81. int(13)
  82. int(4)
  83. int(13)
  84. int(4)
  85. int(13)
  86. int(4)
  87. int(13)
  88. int(4)
  89. int(13)
  90. -- Greek Strings --
  91. int(2)
  92. int(11)
  93. int(2)
  94. int(11)
  95. int(2)
  96. int(11)
  97. int(2)
  98. int(11)
  99. int(2)
  100. int(11)
  101. int(2)
  102. int(11)
  103. int(2)
  104. int(11)
  105. int(2)
  106. int(11)
  107. int(2)
  108. int(11)
  109. int(2)
  110. int(11)
  111. int(2)
  112. int(11)
  113. int(2)
  114. int(11)
  115. Done