You can use:
$input = "foo bar baz saz";
if(preg_match_all('/\s{2,}/',$input,$matches)) {
var_dump($matches);
}
Conclusion:
array(1) {
[0]=>
array(2) {
[0]=>
string(2) " "
[1]=>
string(3) " "
}
}
\s represents a space, which includes space, vertical tab, horizontal tab, reverse carriage, new line, channel form.
If you want to match only regular spaces, you can use a regex:
if(preg_match_all('/ {2,}/',$input,$matches)) {
source
share