PHP » Strings » trim()

Syntax:
string trim(string s [, string remove_list])
s
The string.
remove_list
Characters to remove.

Trims whitespace off a string.

This function returns a new string with the whitespace trimmed off both sides of the input string. By default, this includes tabs, new line characters, and null. The optional remove_list parameter can be used to specify which characters should be trimmed off.

Examples

Code:
<?php

$s1 = trim("   \t  hello there   \n");
$s2 = trim("--- hello ---", "-");
printf("[%s]<br>[%s]", $s1, $s2);

?>
Output:
[hello there]
[ hello ]
Explanation:

trim() is used on two strings, both with and without the use of remove_list. Note that the spaces are left in $s2.

See Also: