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