]> granicus.if.org Git - php/blob
223a839f58
[php] /
1 --TEST--
2 Testing 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 */
21 echo "\n*** Checking with OBJECTS ***\n";
22 class string1 {
23   public function __toString() {
24     return "Object";
25   }
26 }
27 $obj = new string1;
28 var_dump( rtrim($obj, "tc") );
29
30 /* String with embedded NULL */
31 echo "\n*** String with embedded NULL ***\n";
32 var_dump( rtrim("234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
33
34 /* heredoc string */
35 $str = <<<EOD
36 us
37 ing heredoc string
38 EOD;
39
40 echo "\n *** Using heredoc string ***\n";
41 var_dump( rtrim($str, "ing") );
42
43 echo "Done\n";
44 ?>
45 --EXPECTF--
46 *** Output for Normal Behaviour ***
47 string(10) "rtrim test"
48 string(13) "rtrim test   "
49 string(18) "rtrim test        "
50 string(18) "rtrim test        "
51 string(10) "rtrim test"
52 string(11) "rtrim test "
53 string(10) "rtrim test"
54 string(10) "rtrim test"
55 string(10) "rtrim test"
56
57 *** Checking with OBJECTS ***
58 string(4) "Obje"
59
60 *** String with embedded NULL ***
61 string(22) "234\005678\000efgh\xijkl"
62
63  *** Using heredoc string ***
64 string(18) "us
65 ing heredoc str"
66 Done