[PHP] Re: Quickly verifying single word.
- Date: Wed, 04 Jun 2008 19:02:39 -0500
- From: Shawn McKenzie <nospam@xxxxxxxxxxxxx>
- Subject: [PHP] Re: Quickly verifying single word.
Shawn McKenzie wrote:
Tyson Vanover wrote:
I need a quick way to make sure that a string is a single word with no
white spaces. I would prefer that it is a command that could fit on a
single line. Or at least an if block.
I have a few thoughts on this but it involves things like explode(),
stripslashes(), etc.
if (strpos($string, ' ') === false) {
//may not work for tabs, newlines etc
echo 'No spaces!';
}
if (preg_match('/[\s]*/', $string) === false) {
echo 'No spaces!';
}
-Shawn
Second one doesn't work for some reason. No time now to test, will later.
-Shawn
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php