如何在PHP中实现string的strip/remove全部spaces?
我有一个string像$string = "this is my string";
输出应该是"thisismystring"
我该怎么做?
如何在PHP中实现string的strip/remove全部spaces?
我有一个string像$string = "this is my string";
输出应该是"thisismystring"
我该怎么做?
你是指空格还是全部空白?
仅对于空格,请使用str_replace:
$string = str_replace(' ', '', $string);
对于所有空格(包括制表符和行尾),请使用preg_replace:
$string = preg_replace('/\s+/', '', $string);
(从here开始).