xref: /PHP-8.0/ext/standard/tests/strings/rtrim.phpt (revision 5dafd7b4)
1--TEST--
2Testing rtrim() function
3--FILE--
4<?php
5
6/* Testing the Normal behaviour of rtrim() function */
7
8 echo "\n *** Output for Normal Behaviour ***\n";
9 var_dump ( rtrim("rtrim test   \t\0 ") );                       /* without second Argument */
10 var_dump ( rtrim("rtrim test   " , "") );                       /* no characters in second Argument */
11 var_dump ( rtrim("rtrim test        ", NULL) );                 /* with NULL as second Argument */
12 var_dump ( rtrim("rtrim test        ", true) );                 /* with boolean value as second Argument */
13 var_dump ( rtrim("rtrim test        ", " ") );                  /* with single space as second Argument */
14 var_dump ( rtrim("rtrim test \t\n\r\0\x0B", "\t\n\r\0\x0B") );  /* with multiple escape sequences as second Argument */
15 var_dump ( rtrim("rtrim testABCXYZ", "A..Z") );                 /* with characters range as second Argument */
16 var_dump ( rtrim("rtrim test0123456789", "0..9") );             /* with numbers range as second Argument */
17 var_dump ( rtrim("rtrim test$#@", "#@$") );                     /* with some special characters as second Argument */
18
19
20/* Use of class and objects */
21echo "\n*** Checking with OBJECTS ***\n";
22class string1 {
23  public function __toString() {
24    return "Object";
25  }
26}
27$obj = new string1;
28var_dump( rtrim($obj, "tc") );
29
30/* String with embedded NULL */
31echo "\n*** String with embedded NULL ***\n";
32var_dump( rtrim("234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
33
34/* heredoc string */
35$str = <<<EOD
36us
37ing heredoc string
38EOD;
39
40echo "\n *** Using heredoc string ***\n";
41var_dump( rtrim($str, "ing") );
42
43echo "Done\n";
44?>
45--EXPECT--
46*** Output for Normal Behaviour ***
47string(10) "rtrim test"
48string(13) "rtrim test   "
49string(18) "rtrim test        "
50string(18) "rtrim test        "
51string(10) "rtrim test"
52string(11) "rtrim test "
53string(10) "rtrim test"
54string(10) "rtrim test"
55string(10) "rtrim test"
56
57*** Checking with OBJECTS ***
58string(4) "Obje"
59
60*** String with embedded NULL ***
61string(22) "234�05678�00efgh\xijkl"
62
63 *** Using heredoc string ***
64string(18) "us
65ing heredoc str"
66Done
67