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