1--TEST-- 2Test stripos() function : usage variations - double quoted strings for 'haystack' & 'needle' arguments 3--FILE-- 4<?php 5/* Prototype : int stripos ( string $haystack, string $needle [, int $offset] ); 6 * Description: Find position of first occurrence of a case-insensitive string 7 * Source code: ext/standard/string.c 8*/ 9 10/* Test stripos() function by passing double quoted strings for 'haystack' & 'needle' arguments */ 11 12echo "*** Testing stripos() function: with double quoted strings ***\n"; 13$haystack = "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 "; 14$needle = array( 15 //regular strings 16 "l", 17 "L", 18 "HELLO", 19 "hEllo", 20 21 //escape characters 22 "\t", 23 "\T", //invalid input 24 " ", 25 "\n", 26 "\N", //invalid input 27 " 28", //new line 29 30 //nulls 31 "\0", 32 NULL, 33 null, 34 35 //boolean false 36 FALSE, 37 false, 38 39 //empty string 40 "", 41 42 //special chars 43 " ", 44 "$", 45 " $", 46 "&", 47 "!#", 48 "%\o", 49 "\o,", 50 "()", 51 "*+", 52 "+", 53 "-", 54 ".", 55 ".;", 56 ":;", 57 ";", 58 "<=>", 59 ">", 60 "=>", 61 "?", 62 "@", 63 "@hEllo", 64 65 "12345", //decimal numeric string 66 "\x23", //hexadecimal numeric string 67 "#", //respective ASCII char of \x23 68 "\101", //octal numeric string 69 "A", //respective ASCII char of \101 70 "456HEE", //numerics + chars 71 $haystack //haystack as needle 72); 73 74/* loop through to get the position of the needle in haystack string */ 75$count = 1; 76for($index=0; $index<count($needle); $index++) { 77 echo "-- Iteration $count --\n"; 78 var_dump( stripos($haystack, $needle[$index]) ); 79 var_dump( stripos($haystack, $needle[$index], $index) ); 80 $count++; 81} 82echo "*** Done ***"; 83?> 84--EXPECTF-- 85*** Testing stripos() function: with double quoted strings *** 86-- Iteration 1 -- 87int(2) 88int(2) 89-- Iteration 2 -- 90int(2) 91int(2) 92-- Iteration 3 -- 93int(0) 94int(34) 95-- Iteration 4 -- 96int(0) 97int(34) 98-- Iteration 5 -- 99int(6) 100int(6) 101-- Iteration 6 -- 102bool(false) 103bool(false) 104-- Iteration 7 -- 105bool(false) 106bool(false) 107-- Iteration 8 -- 108int(7) 109int(7) 110-- Iteration 9 -- 111bool(false) 112bool(false) 113-- Iteration 10 -- 114int(7) 115int(9) 116-- Iteration 11 -- 117int(8) 118bool(false) 119-- Iteration 12 -- 120 121Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 122int(8) 123 124Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 125bool(false) 126-- Iteration 13 -- 127 128Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 129int(8) 130 131Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 132bool(false) 133-- Iteration 14 -- 134 135Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 136int(8) 137 138Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 139bool(false) 140-- Iteration 15 -- 141 142Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 143int(8) 144 145Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d 146bool(false) 147-- Iteration 16 -- 148bool(false) 149bool(false) 150-- Iteration 17 -- 151int(10) 152int(47) 153-- Iteration 18 -- 154int(12) 155bool(false) 156-- Iteration 19 -- 157int(11) 158bool(false) 159-- Iteration 20 -- 160int(13) 161bool(false) 162-- Iteration 21 -- 163int(14) 164bool(false) 165-- Iteration 22 -- 166int(16) 167bool(false) 168-- Iteration 23 -- 169int(17) 170bool(false) 171-- Iteration 24 -- 172int(20) 173bool(false) 174-- Iteration 25 -- 175int(22) 176bool(false) 177-- Iteration 26 -- 178int(23) 179bool(false) 180-- Iteration 27 -- 181int(24) 182bool(false) 183-- Iteration 28 -- 184int(25) 185bool(false) 186-- Iteration 29 -- 187bool(false) 188bool(false) 189-- Iteration 30 -- 190int(27) 191bool(false) 192-- Iteration 31 -- 193int(28) 194bool(false) 195-- Iteration 32 -- 196int(29) 197bool(false) 198-- Iteration 33 -- 199int(31) 200bool(false) 201-- Iteration 34 -- 202int(30) 203bool(false) 204-- Iteration 35 -- 205int(32) 206bool(false) 207-- Iteration 36 -- 208int(33) 209bool(false) 210-- Iteration 37 -- 211int(33) 212bool(false) 213-- Iteration 38 -- 214int(39) 215int(39) 216-- Iteration 39 -- 217int(15) 218int(48) 219-- Iteration 40 -- 220int(15) 221int(48) 222-- Iteration 41 -- 223int(51) 224int(51) 225-- Iteration 42 -- 226int(51) 227int(51) 228-- Iteration 43 -- 229bool(false) 230bool(false) 231-- Iteration 44 -- 232int(0) 233bool(false) 234*** Done *** 235