关于php的去掉空格问题: <?php /** * @abstract emit the whitespace of string. * @param $str is the string inputed. * @return $str is the string that emit whitespace. */ function emitWhiteSpace($str) { $str = trim($str); // '?='表示只匹配后面的空格跟随前面的空格的空格。 $str = preg_replace('//s(?=/s)/', '', $str); // 最后将非空格替换为一个空格 $str = preg_replace('/[/n/r/t]/', '', $str); return $str; } ?> 可以处理半角与圆角的去掉空格输出。当然还有另外一种办法,在str_replace中用圆角输入空格来被替换。