How to remove spaces from a string, for example from:
16:15
do
16:15
Answer 1, authority 100%
like this str_replace ('', '', '16: 15 ');
Answer 2, authority 50%
What is really there ..
$ text = '16: 15 ';
$ chars = preg_split ('// u', $ text, null, PREG_SPLIT_NO_EMPTY);
$ resultChars = array_filter ($ chars, function ($ char) {
return! preg_match ('/ / u', $ char);
});
$ result = implode ('', $ resultChars);
var_dump ($ result); // string (5) "16:15"
From the Bad Advice series
Answer 3, authority 40%
$ text = "16: 15";
$ result = preg_replace ("/ \ s + /", "", $ text);
echo $ result;