如果下面的变量不包含任何字符,只有任意数量的空格,我想将用户重定向到使用header("Location: URL"); exit();.   
我怎样才能做到这一点?
$comment = mysql_real_escape_string($_POST['comment']);
    如果下面的变量不包含任何字符,只有任意数量的空格,我想将用户重定向到使用header("Location: URL"); exit();.   
我怎样才能做到这一点?
$comment = mysql_real_escape_string($_POST['comment']);
    这里有2种方法:
if (trim($var, ' ') == '') {
    // $var consists of only spaces
}
// or
if (str_replace(' ', '', $var) == '') {
    // $var consists of only spaces
}
    我会为 PCRE 使用 \s 标识符,这也将捕获标签等:
if (preg_match('/^\s+$/', $comment) { ... }
[编辑] 或者,如果您还想捕获完全空的字符串:
if (preg_match('/^\s*$/', $comment) { ... }
    !trim( $_POST['comment'] ) && header( "Location: URL" );
    if(str_replace(" ", "", $comment) == "")
{
  header("Location: URL");
  exit();
}
    if(strlen(trim($comment)) == 0) header('Location: URL');