Definitions and Usage
The trim () function deletes white space characters and other predefined characters from both ends of the string.
Grammar
Trim (string,charlist) parameter description
String required. Specify the string to check.
Charlist Optional. Specify the string to convert. If this argument is omitted, all of the following characters are deleted:
Copy Code code as follows:
"" "-NULL
"\ T"-tab
"\ n"-New line
"\X0B"-Portrait list character
"\ r"-Carriage return
""-Plain white space character
Example 1
Copy Code code as follows:
<?php
$STR = "Use function trim to remove whitespace characters from both ends of the string";
$str 1 = Trim ($STR); echo "Before processing has". strlen ($STR). Characters ";
echo "<br/>";
echo "<br/>";
echo "processed with the Trim function". strlen ($str 1). Characters ";
?>
Output:
There are 39 characters before processing with the PHP function trim () 34 characters after processing
Example 2
Copy Code code as follows:
<?php
$str = "# #使用函数trim去掉字符串两端特定字符";
$str 1 = Trim ($str, "#"); Pass in the second argument for the function trim, trim will remove the string $str the # character at both ends
echo $str. " <br> ";
echo $str 1;
?>
Output:
# #使用PHP函数trim () remove specific characters at both ends of the string use function trim to remove specific characters at both ends of the string