1--TEST-- 2Test strrchr() function : usage variations - binary safe 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: with binary values & null terminated strings passed to 'str1' & 'str2' */ 11 12echo "*** Test strrchr() function: binary safe ***\n"; 13$haystacks = array( 14 "Hello".chr(0)."World", 15 chr(0)."Hello World", 16 "Hello World".chr(0), 17 chr(0).chr(0).chr(0), 18 "Hello\0world", 19 "\0Hello", 20 "Hello\0" 21); 22 23for($index = 0; $index < count($haystacks); $index++ ) { 24 //needle as null string 25 var_dump( strrchr($haystacks[$index], "\0") ); 26 //needle as NULL 27 var_dump( strrchr($haystacks[$index], NULL) ); 28} 29echo "*** Done ***"; 30?> 31--EXPECTF-- 32*** Test strrchr() function: binary safe *** 33string(6) "World" 34 35Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 36string(6) "World" 37string(12) "Hello World" 38 39Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 40string(12) "Hello World" 41string(1) "" 42 43Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 44string(1) "" 45string(1) "" 46 47Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 48string(1) "" 49string(6) "world" 50 51Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 52string(6) "world" 53string(6) "Hello" 54 55Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 56string(6) "Hello" 57string(1) "" 58 59Deprecated: strrchr(): Non-string needles will be interpreted as strings in %s on line %d 60string(1) "" 61*** Done *** 62