PHP string function-trim () instance usage

Source: Internet
Author: User
Tags rtrim

String Trim (String $str [, String $charlist = "\t\n\r\0\x0b"])
This function returns the result of the string str after removing the trailing whitespace characters. If you do not specify a second parameter, trim () will remove these characters:
1. "" (ASCII (0x20)), ordinary whitespace.
2. "\ T" (ASCII 9 (0x09)), tab.
3. "\ n" (ASCII (0x0A)), line break.
4. "\ R" (ASCII (0x0D)), carriage return.
5. "\" (ASCII 0 (0x00)), null byte character.
6. "\x0b" (ASCII One (0x0B)), Vertical tab.

<?PHP$text= "\t\tthese is a few words:) ... "; $binary= "\x09example string\x0a"; $hello= "Hello World"; $str= "##\t use function trim to remove specific characters at both ends of a string # # #"; $new _text=Trim($text); $new _binary=Trim($binary); $new _hello=Trim($hello); $new _str=Trim($str,"#"); Echo $new _text;//These is a few words:) ...    Echo $new _binary;//Example String    Echo $hello;//Hello World    Echo $new _str;//use function trim to remove specific characters at both ends of a string?>

The above function function, also applies to LTrim (), RTrim (), these 2 functions
1, LTrim (); remove whitespace characters (or other characters) at the beginning of a string
2, RTrim (); remove whitespace characters (or other characters) at the end of a string

PHP string function-trim () instance usage

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.