【问题标题】:Trim does not strip spaces修剪不会去除空格
【发布时间】:2016-03-30 11:59:42
【问题描述】:

我已经阅读了很多答案,但从未找到解决方案。

为什么这不适用于修剪?

$test = trim('Whatever this     is');
echo $test;

这项工作:

$test= preg_replace('/\s+/', ' ', 'Whatever this     is');
echo $test;

预期:

Whatever this is

为什么第一个不起作用,而第二个起作用?没有奇怪的字符,因为我是直接在 PHP 代码中编写的。

请不要关闭太快

【问题讨论】:

  • php.net 上trim() 的第一句话:trim — 从字符串的开头和结尾去除空格(或其他字符)
  • 显然并非仅用于查看目的。
  • @Daan 第一句话其实是“China PHP Conference 2016”,不过是的,谢谢!

标签: php string trim


【解决方案1】:

trim 仅从字符串的开头和结尾去除空格。请参考这个link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-23
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2014-12-25
    相关资源
    最近更新 更多