xref: /PHP-7.3/ext/standard/tests/strings/ltrim.phpt (revision 782352c5)
1--TEST--
2Test ltrim() 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
12 echo "\n *** Output for zero argument ***\n";
13 var_dump( ltrim() );
14
15 echo "\n *** Output for more than valid number of arguments (Valid are 1 or 2 arguments) ***\n";
16 var_dump( ltrim("", " ", 1) );
17
18/* heredoc string */
19$str = <<<EOD
20us
21ing heredoc string
22EOD;
23
24echo "\n *** Using heredoc string ***\n";
25var_dump( ltrim($str, "\nusi") );
26
27/* Testing the Normal behaviour of ltrim() function */
28
29 echo "\n *** Output for Normal Behaviour ***\n";
30 var_dump ( ltrim(" \t\0    ltrim test") );                      /* without second Argument */
31 var_dump ( ltrim("   ltrim test" , "") );                       /* no characters in second Argument */
32 var_dump ( ltrim("        ltrim test", NULL) );                 /* with NULL as second Argument */
33 var_dump ( ltrim("        ltrim test", true) );                 /* with boolean value as second Argument */
34 var_dump ( ltrim("        ltrim test", " ") );                  /* with single space as second Argument */
35 var_dump ( ltrim("\t\n\r\0\x0B ltrim test", "\t\n\r\0\x0B") );  /* with multiple escape sequences as second Argument */
36 var_dump ( ltrim("ABCXYZltrim test", "A..Z") );                 /* with characters range as second Argument */
37 var_dump ( ltrim("0123456789ltrim test", "0..9") );             /* with numbers range as second Argument */
38 var_dump ( ltrim("@$#ltrim test", "#@$") );                     /* with some special characters as second Argument */
39
40
41 echo "\n *** Output for  scalar argument) ***\n";
42 var_dump( ltrim(  12345  ) );                                   /* Scalar argument */
43
44 echo "\n *** Output for  NULL argument) ***\n";
45 var_dump( ltrim(NULL) );                                        /* NULL Argument */
46
47echo "\nDone\n";
48
49?>
50--EXPECTF--
51*** Output for Error Conditions ***
52
53 *** Output for zero argument ***
54
55Warning: ltrim() expects at least 1 parameter, 0 given in %s on line %d
56NULL
57
58 *** Output for more than valid number of arguments (Valid are 1 or 2 arguments) ***
59
60Warning: ltrim() expects at most 2 parameters, 3 given in %s on line %d
61NULL
62
63 *** Using heredoc string ***
64string(17) "ng heredoc string"
65
66 *** Output for Normal Behaviour ***
67string(10) "ltrim test"
68string(13) "   ltrim test"
69string(18) "        ltrim test"
70string(18) "        ltrim test"
71string(10) "ltrim test"
72string(11) " ltrim test"
73string(10) "ltrim test"
74string(10) "ltrim test"
75string(10) "ltrim test"
76
77 *** Output for  scalar argument) ***
78string(5) "12345"
79
80 *** Output for  NULL argument) ***
81string(0) ""
82
83Done
84