Implementation of the TRIM function code in PHP _php tutorial

Source: Internet
Author: User
Remove the space before and after.

Suppose there is a string "DDD dd D", after trim () becomes "DDD dd D".

If you can remove the extra space on both sides (including tabs), but not the middle space.
The trim () function in PHP is the same as the use of the trim () function in ASP, which is naturally used if you have been exposed to ASP.
The usage is simple, add the following in the variable where you want to remove the space:
Echo Trim ($ variable);
?>

Generally used in the user's password processing.

Definition and usage
The trim () function removes white-space characters and other predefined characters from both ends of the string.

Grammar
Trim (string,charlist) parameter description
string is required. Specifies the string to check.
Charlist is optional. Specifies the string to convert. If this argument is omitted, all of the following characters are removed:
"+"-NULL
"\ T"-tab
"\ n"-New line
"\x0b"-Vertical list character
"\ r"-Enter
""-Plain white space character
Example 1
Copy CodeThe code is as follows:


$str = "Hello world!";
echo "without Trim:". $STR;
echo "
";
echo "with Trim:". Trim ($STR);
?>



Output:
Copy CodeThe code is as follows:
Without Trim:hello world!
With Trim:hello world! HTML Source:


Example 2
Copy CodeThe code is as follows:
$str = "\r\nhello world!\r\n";
echo "without Trim:". $STR;
echo "
";
echo "with Trim:". Trim ($STR);
?>

Output:

Without Trim:hello world!
With Trim:hello world! Html

http://www.bkjia.com/PHPjc/318090.html www.bkjia.com true http://www.bkjia.com/PHPjc/318090.html techarticle Remove the space before and after. Assume that there is a string "dddddd", after trim () becomes "dddddd". If you can remove the extra spaces on both sides (including tabs), but not the middle space ...

  • 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.