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