mb_stripos_variation5_Bug45923.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --TEST--
  2. Test mb_stripos() function : usage variations - Pass different integers as $offset argument
  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 how mb_stripos() behaves when passed different integers as $offset argument
  17. * The character length of $string_ascii and $string_mb is the same,
  18. * and the needle appears at the same positions in both strings
  19. */
  20. mb_internal_encoding('UTF-8');
  21. echo "*** Testing mb_stripos() : usage variations ***\n";
  22. $string_ascii = b'+Is an English string'; //21 chars
  23. $needle_ascii = b'G';
  24. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
  25. $needle_mb = base64_decode('44CC');
  26. /*
  27. * Loop through integers as multiples of ten for $offset argument
  28. * mb_stripos should not be able to accept negative values as $offset.
  29. * 60 is larger than *BYTE* count for $string_mb
  30. */
  31. for ($i = -10; $i <= 60; $i += 10) {
  32. echo "\n**-- Offset is: $i --**\n";
  33. echo "-- ASCII String --\n";
  34. var_dump(mb_stripos($string_ascii, $needle_ascii, $i));
  35. echo "--Multibyte String --\n";
  36. var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8'));
  37. }
  38. echo "Done";
  39. ?>
  40. --EXPECTF--
  41. *** Testing mb_stripos() : usage variations ***
  42. **-- Offset is: -10 --**
  43. -- ASCII String --
  44. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  45. bool(false)
  46. --Multibyte String --
  47. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  48. bool(false)
  49. **-- Offset is: 0 --**
  50. -- ASCII String --
  51. int(9)
  52. --Multibyte String --
  53. int(9)
  54. **-- Offset is: 10 --**
  55. -- ASCII String --
  56. int(20)
  57. --Multibyte String --
  58. int(20)
  59. **-- Offset is: 20 --**
  60. -- ASCII String --
  61. int(20)
  62. --Multibyte String --
  63. int(20)
  64. **-- Offset is: 30 --**
  65. -- ASCII String --
  66. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  67. bool(false)
  68. --Multibyte String --
  69. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  70. bool(false)
  71. **-- Offset is: 40 --**
  72. -- ASCII String --
  73. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  74. bool(false)
  75. --Multibyte String --
  76. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  77. bool(false)
  78. **-- Offset is: 50 --**
  79. -- ASCII String --
  80. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  81. bool(false)
  82. --Multibyte String --
  83. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  84. bool(false)
  85. **-- Offset is: 60 --**
  86. -- ASCII String --
  87. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  88. bool(false)
  89. --Multibyte String --
  90. Warning: mb_stripos(): Offset not contained in string in %s on line %d
  91. bool(false)
  92. Done