以前没看trim函数以为他只能删除空白,今天发现它还可以删除"" - null.
"t" - tab ,"n" - new line ,"x0b" - 纵向列表符 ,"r" - 回车 ," " - 普通空白字符,以及用户指定字符.
定义和用法:trim() 函数从字符串的两端删除空白字符和其他预定义字符,可选,规定要转换的字符串,如果省略该参数,则删除以下所有字符:
"" - null,"t" - tab,"n" - new line,"x0b" - 纵向列表符,"r" - 回车," " - 普通空白字符,实例代码如下:
- <?php
- $str = " this line containstliberal rn use of whitespace.nn";
-
-
- $str = trim($str);
-
-
- $str = preg_replace('/s(?=s)/', '', $str);
-
-
- $str = preg_replace('/[nrt]/', ' ', $str);
- echo "<pre>{$str}</pre>";
-
- <?php
- $str = "##使用函数trim去掉字符串两端特定字符####";
- $str1 = trim($str,"#");
-
- echo $str."<br>";
- echo $str1;
- ?>
- ?>
|