1--TEST-- 2Test stripos() function : usage variations - single 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 single quoted strings to 'haystack' & 'needle' arguments */ 11 12echo "*** Testing stripos() function: with single 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', 24 ' ', 25 '\n', 26 '\N', 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 '@', 64 '@hEllo', 65 66 '12345', //decimal numeric string 67 '\x23', //hexadecimal numeric string 68 '#', //hexadecimal numeric string 69 '\101', //octal numeric string 70 'A', 71 '456HEE', //numerics + chars 72 42, //needle as int(ASCII value of '*') 73 $haystack //haystack as needle 74); 75 76/* loop through to get the position of the needle in haystack string */ 77$count = 1; 78for($index=0; $index<count($needle); $index++) { 79 echo "-- Iteration $count --\n"; 80 var_dump( stripos($haystack, $needle[$index]) ); 81 var_dump( stripos($haystack, $needle[$index], $index) ); 82 $count++; 83} 84echo "*** Done ***"; 85?> 86--EXPECTF-- 87*** Testing stripos() function: with single quoted strings *** 88-- Iteration 1 -- 89int(2) 90int(2) 91-- Iteration 2 -- 92int(2) 93int(2) 94-- Iteration 3 -- 95int(0) 96int(38) 97-- Iteration 4 -- 98int(0) 99int(38) 100-- Iteration 5 -- 101int(6) 102int(6) 103-- Iteration 6 -- 104int(6) 105int(6) 106-- Iteration 7 -- 107bool(false) 108bool(false) 109-- Iteration 8 -- 110int(8) 111int(8) 112-- Iteration 9 -- 113int(8) 114int(8) 115-- Iteration 10 -- 116bool(false) 117bool(false) 118-- Iteration 11 -- 119int(10) 120int(10) 121-- Iteration 12 -- 122 123Deprecated: 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 124bool(false) 125 126Deprecated: 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 127bool(false) 128-- Iteration 13 -- 129 130Deprecated: 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 131bool(false) 132 133Deprecated: 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 134bool(false) 135-- Iteration 14 -- 136 137Deprecated: 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 138bool(false) 139 140Deprecated: 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 141bool(false) 142-- Iteration 15 -- 143 144Deprecated: 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 145bool(false) 146 147Deprecated: 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 148bool(false) 149-- Iteration 16 -- 150bool(false) 151bool(false) 152-- Iteration 17 -- 153int(14) 154int(51) 155-- Iteration 18 -- 156int(16) 157bool(false) 158-- Iteration 19 -- 159int(15) 160bool(false) 161-- Iteration 20 -- 162int(17) 163bool(false) 164-- Iteration 21 -- 165int(18) 166bool(false) 167-- Iteration 22 -- 168int(20) 169bool(false) 170-- Iteration 23 -- 171int(21) 172bool(false) 173-- Iteration 24 -- 174int(24) 175int(24) 176-- Iteration 25 -- 177int(26) 178int(26) 179-- Iteration 26 -- 180int(27) 181int(27) 182-- Iteration 27 -- 183int(28) 184int(28) 185-- Iteration 28 -- 186int(29) 187int(29) 188-- Iteration 29 -- 189bool(false) 190bool(false) 191-- Iteration 30 -- 192bool(false) 193bool(false) 194-- Iteration 31 -- 195int(31) 196int(31) 197-- Iteration 32 -- 198int(32) 199int(32) 200-- Iteration 33 -- 201int(33) 202int(33) 203-- Iteration 34 -- 204int(35) 205int(35) 206-- Iteration 35 -- 207int(34) 208int(34) 209-- Iteration 36 -- 210int(36) 211int(36) 212-- Iteration 37 -- 213int(37) 214int(37) 215-- Iteration 38 -- 216int(37) 217int(37) 218-- Iteration 39 -- 219int(43) 220int(43) 221-- Iteration 40 -- 222int(52) 223int(52) 224-- Iteration 41 -- 225int(19) 226bool(false) 227-- Iteration 42 -- 228int(58) 229int(58) 230-- Iteration 43 -- 231bool(false) 232bool(false) 233-- Iteration 44 -- 234bool(false) 235bool(false) 236-- Iteration 45 -- 237 238Deprecated: 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 239int(26) 240 241Deprecated: 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 242bool(false) 243-- Iteration 46 -- 244int(0) 245bool(false) 246*** Done *** 247