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"
34string(6) "�World"
35string(12) "�Hello World"
36string(12) "�Hello World"
37string(1) "�"
38string(1) "�"
39string(1) "�"
40string(1) "�"
41string(6) "�world"
42string(6) "�world"
43string(6) "�Hello"
44string(6) "�Hello"
45string(1) "�"
46string(1) "�"
47*** Done ***
48