2012-06-25 4 views
0

아래 변수가 공백이 아닌 문자로 구성된 경우 header("Location: URL"); exit();을 사용하여 URL로 리디렉션하고 싶습니다.변수가 공백으로 구성된 경우 사용자를 URL로 리디렉션

어떻게하면됩니까?

if (trim($var, ' ') == '') { 
    // $var consists of only spaces 
} 

// or 

if (str_replace(' ', '', $var) == '') { 
    // $var consists of only spaces 
} 

답변

0
if(strlen(trim($comment)) == 0) header('Location: URL'); 
0
!trim($_POST['comment']) && header("Location: URL"); 
2

는 다음 2 가지 방법 ] 또는 완전히 빈 문자열을 잡으려면 :

내가 생각하는
1
내가 PCRE의 \의 식별자를 사용하십시오

, 이것은 또한 탭을 잡을 것 같은 :

if (preg_match('/^\s+$/', $comment) { ... } 

[편집

$comment = mysql_real_escape_string($_POST['comment']); 
+0

는'preg_match'는'trim' 같은 간단한 문자열 함수는 동일한 효과가 맨 위에 조금 사용할 수있는 경우? –

0
if(str_replace(" ", "", $comment) == "") 
{ 
    header("Location: URL"); 
    exit(); 
} 
관련 문제