是否有php函数来删除字符串中的空格?例如: $ abcd =“这是一个测试” 我想得到字符串: $ ABCD = “thisisatest”
怎么做?谢谢。
答案 0 :(得分:14)
$abcd = str_replace(' ', '', 'this is a test');
答案 1 :(得分:3)
以下内容也适用
$abcd="this is a test";
$abcd = preg_replace('/( *)/', '', $abcd);
echo $abcd."\n"; //Will output 'thisisatest';
或
$abcd = preg_replace('/\s/', '', $abcd);
答案 2 :(得分:0)
$string = preg_replace('/\s+/', '', $string);