Home >Backend Development >PHP Tutorial >过滤空格,急在线等

过滤空格,急在线等

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:23:591098browse

如$str="  沃尔克   ·   布鲁赫 ";
怎样过滤掉(沃尔克   ·   布鲁赫)前面与后面的空格,保留中间部分的空格。


回复讨论(解决方案)

str_replace( "   ", " ",$str); 

替换

echo preg_replace('/^\s+|\s+$/','',$str);

$str="  沃尔克   ·   布鲁赫 ";
echo trim($str);

$str="  沃尔克   ·   布鲁赫 ";
echo trim($str); +1

$str="  沃尔克   ·   布鲁赫 ";
echo trim($str);
trim是删除两端的吧

PHP trim() 函数
http://www.w3school.com.cn/php/func_string_trim.asp
可以去除首尾空格


$str="  沃尔克   ·   布鲁赫 ";
echo trim($str);
trim是删除两端的吧
是的。
过滤掉(沃尔克   ·   布鲁赫)前面与后面的空格,保留中间部分的空格。 就是过滤两端的意思。

Statement:
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