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