Php trim () function example

Source: Internet
Author: User

Php trim () function example

The php trim () function removes white spaces or other pre-defined characters on both sides of the string. This article introduces the usage and examples of the php trim () function to coders, for more information, see.

Definition and usage

The trim () function removes spaces or other predefined characters on both sides of a string.

Related functions:
  • Ltrim ()-removes white spaces or other predefined characters from the left of the string.
  • Rtrim ()-removes spaces or other predefined characters from the right of the string

 

Syntax
trim(string,charlist)

 

Parameters Description
String Required. Specifies the string to be checked.
Charlist

Optional. Specifies which characters are deleted from the string. If omitted, all the following characters are removed:

  • "\ 0"-NULL
  • "\ T"-Tab
  • "\ N"-line feed
  • "\ X0B"-vertical Tab
  • "\ R"-press ENTER
  • ""-Space

 

Technical details
Return Value: Returns the modified string.
PHP version: 4 +
Update log: In PHP 4.1CharlistParameters.

 

Instance

Remove spaces on both sides of the string:

<? Php $ str = "Hello World! "; Echo" trim: ". $ str; echo" <br> "; echo" trim: ". trim ($ str);?>

Online operation

The HTML output of the above Code is as follows (check the source code ):

<! DOCTYPE html> <body> trim: Hello World is not used! <Br> use trim: Hello World! </Body> 

The browser output of the above Code is as follows:

Do not use trim: Hello World! Use trim: Hello World!

Address: http://www.manongjc.com/article/827.html

Related reading:

The php trim () function removes spaces or other predefined characters on both sides of the string.

The php rtrim () function removes the white space or other predefined characters on the right of the string.

The php trim () function removes spaces or other predefined characters on both sides 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.