PHP string removes space

Is there a php function to remove space inside a string? for example: $ abcd = "this is a test" I want to get the line: $ ABCD = "thisisatest"

How to do it? Thank you

+4
source share
3 answers

Following will work

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

or

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

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

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

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

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

Source: https://habr.com/ru/post/1307372/


All Articles