php function trim () definition and syntax introduction _php tutorial

Source: Internet
Author: User
Everyone is writing Definition and Usage

The PHP function trim () removes whitespace characters and other predefined characters from both ends of the string.

Grammar

Trim (str,charlist) parameter 1 str is the string to be manipulated, parameter 2 charlist optional, specifies the special symbol you want to remove.

If the second parameter does not give a value, the preset removes the following characters:

 
  
  
  1. "(ASCII (0x20)), an ordinary space.
  2. "T" (ASCII 9 (0x09)), a tab.
  3. "N" (ASCII (0x0A)), a new line (line feed).
  4. "R" (ASCII (0x0D)), a carriage return.
  5. "" (ASCII 0 (0x00)), the Nul-byte.
  6. "x0b" (ASCII One (0x0B)), a vertical tab.

If you want to remove other characters, you can set it in the second parameter.

Example 1

 
 
  1. PHP
  2. $ Str = "Use function trim to remove whitespace characters at both ends of a string" ;
  3. $ str1 = Trim ($STR);
  4. echo "Before processing". strlen ($STR). " Characters "; echo "<br/>";
  5. //www.phpjc.cn echo " < BR /> ";
  6. echo "has been processed with the trim function". strlen ($str 1). " Characters ";
  7. ?>

Output:

39 characters before processing 34 characters after using the PHP function trim ()

Example 2

 
  
  
  1. Php
  2. $ Str # #使用函数trim去掉字符串两端特定字符 # #
  3. $ str1 Trim
  4. Pass in the second argument for function trim,
    Trim will delete the string $str at both ends of the # character Echo $str. " < BR >
  5. ?>

Output:

# #使用PHP函数trim () remove specific characters at both ends of a string # # # # Use function trim to remove specific characters at both ends


http://www.bkjia.com/PHPjc/446304.html www.bkjia.com true http://www.bkjia.com/PHPjc/446304.html techarticle everyone writes definitions and uses the PHP function trim () to remove whitespace characters and other predefined characters from both ends of the string. Syntax Trim (str,charlist) parameter 1 str is the string to be manipulated, parameters ...

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