1--TEST-- 2Test strrpos() function : usage variations - single quoted strings for 'haystack' & 'needle' arguments 3--FILE-- 4<?php 5/* Prototype : int strrpos ( string $haystack, string $needle [, int $offset] ); 6 * Description: Find position of last occurrence of 'needle' in 'haystack'. 7 * Source code: ext/standard/string.c 8*/ 9 10/* Test strrpos() function by passing single quoted strings to 'haystack' & 'needle' arguments */ 11 12echo "*** Testing strrpos() function: with single quoted strings ***\n"; 13$haystack = 'Hello,\t\n\0\n $&!#%()*<=>?@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 '()', 49 '<=>', 50 '>', 51 '=>', 52 '?', 53 '@', 54 '@hEllo', 55 56 '12345', //decimal numeric string 57 '\x23', //hexadecimal numeric string 58 '#', //hexadecimal numeric string 59 '\101', //octal numeric string 60 'A', 61 '456HEE', //numerics + chars 62 42, //needle as int(ASCII value of '*') 63 $haystack //haystack as needle 64); 65 66/* loop through to get the position of the needle in haystack string */ 67$count = 1; 68for($index=0; $index<count($needle); $index++) { 69 echo "-- Iteration $count --\n"; 70 var_dump( strrpos($haystack, $needle[$index]) ); 71 var_dump( strrpos($haystack, $needle[$index], $index) ); 72 $count++; 73} 74echo "*** Done ***"; 75?> 76--EXPECTF-- 77*** Testing strrpos() function: with single quoted strings *** 78-- Iteration 1 -- 79int(32) 80int(32) 81-- Iteration 2 -- 82bool(false) 83bool(false) 84-- Iteration 3 -- 85bool(false) 86bool(false) 87-- Iteration 4 -- 88bool(false) 89bool(false) 90-- Iteration 5 -- 91int(6) 92int(6) 93-- Iteration 6 -- 94bool(false) 95bool(false) 96-- Iteration 7 -- 97bool(false) 98bool(false) 99-- Iteration 8 -- 100int(12) 101int(12) 102-- Iteration 9 -- 103bool(false) 104bool(false) 105-- Iteration 10 -- 106bool(false) 107bool(false) 108-- Iteration 11 -- 109int(10) 110int(10) 111-- Iteration 12 -- 112 113Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 114bool(false) 115 116Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 117bool(false) 118-- Iteration 13 -- 119 120Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 121bool(false) 122 123Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 124bool(false) 125-- Iteration 14 -- 126 127Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 128bool(false) 129 130Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 131bool(false) 132-- Iteration 15 -- 133 134Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 135bool(false) 136 137Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 138bool(false) 139-- Iteration 16 -- 140bool(false) 141bool(false) 142-- Iteration 17 -- 143int(53) 144int(53) 145-- Iteration 18 -- 146int(16) 147bool(false) 148-- Iteration 19 -- 149int(15) 150bool(false) 151-- Iteration 20 -- 152int(17) 153bool(false) 154-- Iteration 21 -- 155int(18) 156bool(false) 157-- Iteration 22 -- 158int(21) 159int(21) 160-- Iteration 23 -- 161int(24) 162int(24) 163-- Iteration 24 -- 164int(26) 165int(26) 166-- Iteration 25 -- 167int(25) 168int(25) 169-- Iteration 26 -- 170int(27) 171int(27) 172-- Iteration 27 -- 173int(28) 174int(28) 175-- Iteration 28 -- 176bool(false) 177bool(false) 178-- Iteration 29 -- 179int(34) 180int(34) 181-- Iteration 30 -- 182int(43) 183int(43) 184-- Iteration 31 -- 185int(19) 186bool(false) 187-- Iteration 32 -- 188int(49) 189int(49) 190-- Iteration 33 -- 191bool(false) 192bool(false) 193-- Iteration 34 -- 194bool(false) 195bool(false) 196-- Iteration 35 -- 197 198Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 199int(23) 200 201Deprecated: strrpos(): Non-string needles will be interpreted as strings in %s on line %d 202bool(false) 203-- Iteration 36 -- 204int(0) 205bool(false) 206*** Done *** 207