Today we bring you the definition and usage of PHP function trim ().
Definitions and usage The trim () function deletes white space characters and other predefined characters from both ends of the string.
Syntax 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:
""-NULL "T"-tab "N"-New line "X0B"-Portrait list character "R"-carriage return ""-Plain white space character
Example 1
<?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:
39 characters before processing 34 characters with the PHP function trim ()
Example 2
<?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 a string
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.