开发者

PHP string remove space

开发者 https://www.devze.com 2022-12-27 22:51 出处:网络
Is there php fun开发者_如何学Goction to remove the space inside the string? for example: $abcd=\"this is a test\"

Is there php fun开发者_如何学Goction to remove the space inside the string? for example:

$abcd="this is a test"

I want to get the string:

$abcd="thisisatest"

How to do that?


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

See http://php.net/manual/en/function.str-replace.php


The following will also work

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

or

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

See manual http://php.net/manual/en/function.preg-replace.php


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

精彩评论

暂无评论...
验证码 换一张
取 消