为什么PHP'的trim()不删除尾随空格?


Why is PHP's trim() not removing trailing blank space?

下面一行没有显示预期的结果:

echo "|".trim(" Laura Suárez Samper ")."|";

以上输出:

|Laura Suárez Samper |

如果我urlencode()空格,我得到:

%e2%80%83

有什么想法吗?

谢谢

我使用了以下unicode安全的修饰:

function unicodeSafeTrim($str)
{
    // unicode-safe trim, removes other and sepatator categories.
    return preg_replace("/^['pZ'pC]+|['pZ'pC]+$/u", "", $str);
}

效果很好