-3

有没有办法测试是否在表单文本输入中按下了空格键。我知道 nthe value 或 keycode 是 32 并尝试了使用以下语句的各种选项:

elseif($rec =='' || $rec == 32 || $rec == ' ')

但仍然无法识别。我将不胜感激,我发布的代码只是我用来检查价值的相关代码的一部分。谢谢

4

2 回答 2

1

查看trim()strstr()函数。我认为这是你需要的。

于 2012-12-09T13:46:22.073 回答
1

使用preg_match()

$subject = "abcdef";
$pattern = '/\s/';
if (preg_match($pattern,)) {...}

使用 PHP strpos()

$mystring = 'Hello world';
$findme   = ' ';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "no spaces :(";
} else {
    echo "Spacing out !!! :)";
}
于 2012-12-09T13:52:05.467 回答