我如何在 PHP 中strip/remove string 的所有空格?
我有一个 string 像 $string = "this is my string";
输出应该是 "thisismystring"
我该怎么做?
最佳答案
你是指空格还是所有空格?
对于空格,使用 str_replace :
$string = str_replace(' ', '', $string);
对于所有空格(包括制表符和行尾),使用 preg_replace :
$string = preg_replace('/\s+/', '', $string);
(来自 here)。
https://stackoverflow.com/questions/2109325/