PHP – detect whitespace between strings

Use preg_match as suggested by Josh:

<?php

$foo = 'Bob Williams';
$bar="SamSpade";
$baz = "Bob\t\t\tWilliams";

var_dump(preg_match('/\s/',$foo));
var_dump(preg_match('/\s/',$bar));
var_dump(preg_match('/\s/',$baz));

Ouputs:

int(1)
int(0)
int(1)

Leave a Comment