1--TEST--
2Test strrchr() function : basic functionality
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
10echo "*** Testing strrchr() function: basic functionality ***\n";
11var_dump( strrchr("Hello, World", "H") ); //needle as single char
12var_dump( strrchr("Hello, World", "Hello") ); //needle as a first word of haystack
13var_dump( strrchr('Hello, World', 'H') );
14var_dump( strrchr('Hello, World', 'Hello') );
15
16//considering case
17var_dump( strrchr("Hello, World", "h") );
18var_dump( strrchr("Hello, World", "hello") );
19
20//needle as second word of haystack
21var_dump( strrchr("Hello, World", "World") );
22var_dump( strrchr('Hello, World', 'World') );
23
24//needle as special char
25var_dump( strrchr("Hello, World", ",") );
26var_dump( strrchr('Hello, World', ',') );
27
28var_dump( strrchr("Hello, World", "Hello, World") ); //needle as haystack
29
30//needle string containing one existing and one non-existing char
31var_dump( strrchr("Hello, World", "Hi") );
32
33//multiple existence of needle in haystack
34var_dump( strrchr("Hello, World", "o") );
35var_dump( strrchr("Hello, World", "ooo") );
36
37var_dump( strrchr("Hello, World", "Zzzz") ); //non-existent needle in haystack
38echo "*** Done ***";
39?>
40--EXPECT--
41*** Testing strrchr() function: basic functionality ***
42string(12) "Hello, World"
43string(12) "Hello, World"
44string(12) "Hello, World"
45string(12) "Hello, World"
46bool(false)
47bool(false)
48string(5) "World"
49string(5) "World"
50string(7) ", World"
51string(7) ", World"
52string(12) "Hello, World"
53string(12) "Hello, World"
54string(4) "orld"
55string(4) "orld"
56bool(false)
57*** Done ***
58