mb_strripos_variation5_Bug45923.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. --TEST--
  2. Test mb_strripos() function : usage variations - Pass different integers as $offset argument
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strripos') or die("skip mb_strripos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_strripos(string haystack, string needle [, int offset [, string encoding]])
  11. * Description: Finds position of last 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_strripos() 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_strripos() : 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_strripos 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_strripos($string_ascii, $needle_ascii, $i));
  35. echo "--Multibyte String --\n";
  36. var_dump(mb_strripos($string_mb, $needle_mb, $i, 'UTF-8'));
  37. }
  38. echo "Done";
  39. ?>
  40. --EXPECTF--
  41. *** Testing mb_strripos() : usage variations ***
  42. **-- Offset is: -10 --**
  43. -- ASCII String --
  44. int(9)
  45. --Multibyte String --
  46. int(9)
  47. **-- Offset is: 0 --**
  48. -- ASCII String --
  49. int(20)
  50. --Multibyte String --
  51. int(20)
  52. **-- Offset is: 10 --**
  53. -- ASCII String --
  54. int(20)
  55. --Multibyte String --
  56. int(20)
  57. **-- Offset is: 20 --**
  58. -- ASCII String --
  59. int(20)
  60. --Multibyte String --
  61. int(20)
  62. **-- Offset is: 30 --**
  63. -- ASCII String --
  64. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  65. bool(false)
  66. --Multibyte String --
  67. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  68. bool(false)
  69. **-- Offset is: 40 --**
  70. -- ASCII String --
  71. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  72. bool(false)
  73. --Multibyte String --
  74. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  75. bool(false)
  76. **-- Offset is: 50 --**
  77. -- ASCII String --
  78. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  79. bool(false)
  80. --Multibyte String --
  81. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  82. bool(false)
  83. **-- Offset is: 60 --**
  84. -- ASCII String --
  85. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  86. bool(false)
  87. --Multibyte String --
  88. Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
  89. bool(false)
  90. Done