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