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 -- 122bool(false) 123bool(false) 124-- Iteration 13 -- 125bool(false) 126bool(false) 127-- Iteration 14 -- 128bool(false) 129bool(false) 130-- Iteration 15 -- 131bool(false) 132bool(false) 133-- Iteration 16 -- 134bool(false) 135bool(false) 136-- Iteration 17 -- 137int(14) 138int(51) 139-- Iteration 18 -- 140int(16) 141bool(false) 142-- Iteration 19 -- 143int(15) 144bool(false) 145-- Iteration 20 -- 146int(17) 147bool(false) 148-- Iteration 21 -- 149int(18) 150bool(false) 151-- Iteration 22 -- 152int(20) 153bool(false) 154-- Iteration 23 -- 155int(21) 156bool(false) 157-- Iteration 24 -- 158int(24) 159int(24) 160-- Iteration 25 -- 161int(26) 162int(26) 163-- Iteration 26 -- 164int(27) 165int(27) 166-- Iteration 27 -- 167int(28) 168int(28) 169-- Iteration 28 -- 170int(29) 171int(29) 172-- Iteration 29 -- 173bool(false) 174bool(false) 175-- Iteration 30 -- 176bool(false) 177bool(false) 178-- Iteration 31 -- 179int(31) 180int(31) 181-- Iteration 32 -- 182int(32) 183int(32) 184-- Iteration 33 -- 185int(33) 186int(33) 187-- Iteration 34 -- 188int(35) 189int(35) 190-- Iteration 35 -- 191int(34) 192int(34) 193-- Iteration 36 -- 194int(36) 195int(36) 196-- Iteration 37 -- 197int(37) 198int(37) 199-- Iteration 38 -- 200int(37) 201int(37) 202-- Iteration 39 -- 203int(43) 204int(43) 205-- Iteration 40 -- 206int(52) 207int(52) 208-- Iteration 41 -- 209int(19) 210bool(false) 211-- Iteration 42 -- 212int(58) 213int(58) 214-- Iteration 43 -- 215bool(false) 216bool(false) 217-- Iteration 44 -- 218bool(false) 219bool(false) 220-- Iteration 45 -- 221int(26) 222bool(false) 223-- Iteration 46 -- 224int(0) 225bool(false) 226*** Done *** 227