Alex Rivera | Logout

PHP - detect whitespace between strings

Asked 2009-07-21T20:58:14.130
33

How would I go about detecting whitespace between strings? For example, I have a name string like:

"Jane Doe"

Keep in mind that I don't want to trim or replace it, just detect if whitespace exists between the first and second string.

Edit
Report

1 Answer

5

You may use something like this:

if (strpos($r, ' ') > 0) {
    echo 'A white space exists between the string';
}
else
{
    echo 'There is no white space in the string';
}

This will detect a space, but not any other kind of whitespace.

answered 2011-08-09T06:28:12.467

Your Answer