Trim 不去掉空格

Trim does not strip spaces

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

为什么这不适用于 trim?

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

这项工作:

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

预期:

Whatever this is

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

请不要太快关闭这个

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