1/* Removes whitespace from beginning and end of a string if
2* the second parameter is omitted
3* First parameter must be the string
4* Second parameter is optional and can include an alternative character or set of characters.
5*/
6
7// Example 1
8$string = " Hello world ";
9$trimmedString = trim($string);
10// Output = 'Hello world',
11
12// Example 2
13$string = "babcabcHello worldabbaca";
14$trimmedString = trim($string, 'abc');
15// Output = 'Hello world',
1<?php
2
3$text = "\t\tThese are a few words :) ... ";
4$binary = "\x09Example string\x0A";
5$hello = "Hello World";
6var_dump($text, $binary, $hello);
7
8print "\n";
9
10$trimmed = trim($text);
11var_dump($trimmed);
12
13$trimmed = trim($text, " \t.");
14var_dump($trimmed);
15
16$trimmed = trim($hello, "Hdle");
17var_dump($trimmed);
18
19$trimmed = trim($hello, 'HdWr');
20var_dump($trimmed);
21
22// trim the ASCII control characters at the beginning and end of $binary
23// (from 0 to 31 inclusive)
24$clean = trim($binary, "\x00..\x1F");
25var_dump($clean);
26
27?>