PHP4 User Manual: function-trim

Source: Internet
Author: User
Tags control characters
TABLEborder0cellPadding0cellSpacing0height100 % width100 % (PHP3, PHP44.0.0) trim -- removes the blank description stringtrim (stringstr [, stringcharlist]) at the beginning and end of a string. note: the second parameter is used in the function PHP4.1.0 to return the str word tag: manual

TABLE border = 0 cellPadding = 0 cellSpacing = 0 height = "100%" width = "100%">

 

(PHP 3, PHP 4> = 4.0.0)

Trim -- removes spaces at the beginning and end of a string.

Description

 

String trim (string str [, string charlist])

 

Note: The second parameter is used in PHP 4.1.0.

This function returns the new string after the str string is removed from the first and last spaces. Without the second parameter trim (), the following characters are removed:

 

"" (ASCII 32 (0x20), space;

"\ T" (ASCII 9 (0x09), tab;

"\ N" (ASCII 10 (0x0A), line break;

"\ R" (ASCII 13 (0x0D), carriage return;

"\ 0" (ASCII 0 (0x00), empty character;

"\ X0B" (ASCII 11 (0x0B), vertical tab.

You can use the charlist parameter to specify the characters you want to remove. Simply list all characters that you want to be stripped. With... you can specify a range of characters.


Example 1. trim ()

$ Text = "\ t \ tThese are a few words :)...";
$ Trimmed = trim ($ text );
// $ Trimmed = "These are a few words :)..."
$ Trimmed = trim ($ text, "\ t .");
// $ Trimmed = "These are a few words :)"
$ Clean = trim ($ binary, "\ 0x00 .. \ 0x1F ");
// Trim the ASCII control characters at the beginning and end of $ binary
// (From 0 to 31 random sive)

?>

 

See ltrim () and rtrim ().

 

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.