Saturday, September 13, 2008

trim() function

The trim() function could be used to remove certain pre-defined characters from both ends of a string.
Syntax: trim(string, [list of characters]);
string- the string in which the predefined characters are to be removed.
list of characters.
\0 for NULL
\t for TAB
\n for new line
“ ” for whitespace
If the list of characters are not specified, all pre-defined characters would be removed.
Example inputs
$first_name = “James ”;
echo $first_name.”
echo first_name;
In the output, the second echo function prints $first_name that has one less space.

$name = “John
echo $name.”
echo $name;
In this case, the second time $name is printed, the new line character is absent.

No comments: