Everyone is writing
Definition and Usage
The PHP function trim () removes whitespace characters and other predefined characters from both ends of the string.
Grammar
Trim (str,charlist) parameter 1 str is the string to be manipulated, parameter 2 charlist optional, specifies the special symbol you want to remove.
If the second parameter does not give a value, the preset removes the following characters:
- "(ASCII (0x20)), an ordinary space.
- "T" (ASCII 9 (0x09)), a tab.
- "N" (ASCII (0x0A)), a new line (line feed).
- "R" (ASCII (0x0D)), a carriage return.
- "" (ASCII 0 (0x00)), the Nul-byte.
- "x0b" (ASCII One (0x0B)), a vertical tab.
If you want to remove other characters, you can set it in the second parameter.
Example 1
- PHP
- $ Str = "Use function trim to remove whitespace characters at both ends of a string" ;
- $ str1 = Trim ($STR);
- echo "Before processing". strlen ($STR). " Characters "; echo "<br/>";
- //www.phpjc.cn echo " < BR /> ";
- echo "has been processed with the trim function". strlen ($str 1). " Characters ";
- ?>
Output:
39 characters before processing 34 characters after using the PHP function trim ()
Example 2
- Php
- $ Str # #使用函数trim去掉字符串两端特定字符 # #
- $ str1 Trim
- Pass in the second argument for function trim,
Trim will delete the string $str at both ends of the # character Echo $str. " < BR >
- ?>
Output:
# #使用PHP函数trim () remove specific characters at both ends of a string # # # # Use function trim to remove specific characters at both ends
http://www.bkjia.com/PHPjc/446304.html www.bkjia.com true http://www.bkjia.com/PHPjc/446304.html techarticle everyone writes definitions and uses the PHP function trim () to remove whitespace characters and other predefined characters from both ends of the string. Syntax Trim (str,charlist) parameter 1 str is the string to be manipulated, parameters ...