xref: /PHP-8.1/ext/standard/tests/strings/trim1.phpt (revision ea256a21)
1--TEST--
2Test trim() function
3--FILE--
4<?php
5/* trim with unset/null/boolean variable - returns an empty string */
6echo "\n";
7$null_var = "";
8var_dump( trim($null_var) );
9$null_var = 0;
10var_dump( trim($null_var) );
11$bool_val = true;
12var_dump( trim($null_var) );
13
14/* second argument charlist as empty - does not trim any white spaces */
15var_dump( trim("\ttesting trim", "") );
16var_dump( trim("\ttesting trim  ", true) );
17
18/* Use of class and objects */
19echo "\n*** Testing with OBJECTS ***\n";
20class string1
21{
22  public function __toString() {
23    return "Object";
24  }
25}
26$obj = new string1;
27var_dump( trim($obj, "Ot") );
28
29/* String with embedded NULL */
30echo "\n*** Testing with String with embedded NULL ***\n";
31var_dump( trim("\x0n1234\x0005678\x0000efgh\xijkl\x0n1", "\x0n1") );
32
33/* heredoc string */
34$str = <<<EOD
35us
36ing heredoc string
37EOD;
38
39echo "\n*** Testing with heredoc string ***\n";
40var_dump( trim($str, "us\ning") );
41
42echo "\nDone";
43?>
44--EXPECTF--
45string(0) ""
46string(1) "0"
47string(1) "0"
48string(13) "	testing trim"
49string(15) "	testing trim  "
50
51*** Testing with OBJECTS ***
52string(4) "bjec"
53
54*** Testing with String with embedded NULL ***
55string(22) "234%005678%000efgh\xijkl"
56
57*** Testing with heredoc string ***
58string(12) " heredoc str"
59
60Done
61