Home > Backend Development > PHP Tutorial > php trim 去除空字符的定义与语法介绍_php技巧

php trim 去除空字符的定义与语法介绍_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-17 09:25:00
Original
903 people have browsed it

定义和用法
trim() 函数从字符串的两端删除空白字符和其他预定义字符。

语法
trim(string,charlist)参数 描述

string 必需。规定要检查的字符串。

charlist 可选。规定要转换的字符串。如果省略该参数,则删除以下所有字符:

复制代码 代码如下:

"\0" - NULL
"\t" - tab
"\n" - new line
"\x0B" - 纵向列表符
"\r" - 回车
" " - 普通空白字符

例子1
复制代码 代码如下:

$str = " 使用函数trim去掉字符串两端空白字符 ";
$str1 = trim($str); echo "处理前有".strlen($str)."个字符";
echo "
";
echo "
";
echo "使用trim函数处理后有".strlen($str1)."个字符";
?>

输出:

处理前有39个字符 使用PHP函数trim()处理后有34个字符

例子2
复制代码 代码如下:

$str = "##使用函数trim去掉字符串两端特定字符####";
$str1 = trim($str,"#"); //为函数trim传入第二个参数,trim将删除字符串$str两端的#字符
echo $str."
";
echo $str1;
?>

输出:
##使用PHP函数trim()去掉字符串两端特定字符#### 使用函数trim去掉字符串两端特定字符
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template