PHP字符串删除空格

时间:2010-04-19 18:11:06

标签: php

是否有php函数来删除字符串中的空格?例如: $ abcd =“这是一个测试” 我想得到字符串: $ ABCD = “thisisatest”

怎么做?谢谢。

3 个答案:

答案 0 :(得分:14)

$abcd = str_replace(' ', '', 'this is a test');

请参阅http://php.net/manual/en/function.str-replace.php

答案 1 :(得分:3)

以下内容也适用

$abcd="this is a test";
$abcd = preg_replace('/( *)/', '', $abcd);
echo $abcd."\n"; //Will output 'thisisatest';

$abcd = preg_replace('/\s/', '', $abcd);

请参阅手册http://php.net/manual/en/function.preg-replace.php

答案 2 :(得分:0)

$string = preg_replace('/\s+/', '', $string);