这个问题在这里已经有了答案:HowcanstripwhitespacesinPHP'svariable?(15个回答)关闭2年前。我如何在PHP中strip/removestring的所有空格?我有一个string像$string="thisismystring";输出应该是"thisismystring"我该怎么做? 最佳答案 你是指空格还是所有空格?对于空格,使用str_replace:$string=str_replace('','',$string);对于所有空格(包括制表符和行尾),使用preg_replace:$stri