欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP trim()函数详解

程序员文章站 2022-03-25 17:52:14
定义 trim 去除字符串里的空白符及其他指定字符 Strip whitespace (or other characters) from the beginning and end of a string 描述 参数 可指定任意字符,使用..可指定一个范围 默认去除下面五个字符 " " (ASCI ......

定义

trim - 去除字符串里的空白符及其他指定字符

strip whitespace (or other characters) from the beginning and end of a string


描述

trim ( string $str [, string $character_mask = " \t\n\r\0\x0b" ] ) : string

参数 character_mask 可指定任意字符,使用..可指定一个范围
默认去除下面五个字符

  • " " (ascii 32 (0x20)), an ordinary space - 普通空白符.
  • "\t" (ascii 9 (0x09)), a tab - 制表符.
  • "\n" (ascii 10 (0x0a)), a new line (line feed) - 换行符.
  • "\r" (ascii 13 (0x0d)), a carriage return - 回车符.
  • "\0" (ascii 0 (0x00)), the nul-byte.
  • "\x0b" (ascii 11 (0x0b)), a vertical tab - 垂直制表符.

示例

trim($text, " \t.");
trim($hello, "hdle");
// (from 0 to 31 inclusive)
trim($binary, "\x00..\x1f");

参看

类似函数,ltrim(),rtrim()