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

过滤空格,急在线等

WBOY
Release: 2016-06-23 14:23:59
Original
1071 people have browsed it

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


回复讨论(解决方案)

str_replace( "   ", " ",$str); 
Copy after login

替换

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

$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是删除两端的吧
是的。
过滤掉(沃尔克   ·   布鲁赫)前面与后面的空格,保留中间部分的空格。 就是过滤两端的意思。

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template