Home  >  Article  >  Backend Development  >  php正则有办法去掉第一段空格吗

php正则有办法去掉第一段空格吗

WBOY
WBOYOriginal
2016-06-23 14:00:34847browse

$str="123            脚本之家 www.jb51.ne      ";
 

最后我需要的是

$str="123脚本之家 www.jb51.ne      ";
 

有什么办法吗


回复讨论(解决方案)

$str="123            脚本之家 www.jb51.ne      ";$p = preg_split ("/\s{2,}/",$str);var_dump(join($p));

";var_dump($tmp);?>
 
有比这个更简单的吗?最好一步到位的

$str="123            脚本之家 www.jb51.ne      ";$p = preg_split ("/\s{2,}/",$str);var_dump(join($p));

ok,我看看

$str="123            脚本之家 www.jb51.ne      ";var_dump(preg_replace('/\s+/', '', $str, 1));

string(29) "123脚本之家 www.jb51.ne      "

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