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
2<?php
3
4$str = "\n\n\nHello World!\n\n\n";
5
6echo "Without trim: " . $str;
7
8echo "<br>";
9
10echo "With trim: " . trim($str);
11
12?>