PHP trim to remove null character definition and syntax introduction _php tips

Source: Internet
Author: User
Tags strlen

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.