The definition and syntax introduction of the TRIM function in PHP to remove null characters

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags check deleted echo function php programming string syntax

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

Related Article

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.