테스트 사이트 - 개발 중인 베타 버전입니다

preg_match 함수 질문드립니다. 채택완료

휴가 10년 전 조회 3,447

if (preg_match("/[<>'^\/]/", $a_mb_id)) die("공격");

 

이렇게 한가지만 검사하면 정상적으로 되는데

 

if (preg_match("/[<>'^\/]/", $a_mb_id, $a_price, $a_shortment)) die("공격");

 

이렇게 $a_mb_id​, $a_price, $a_shortment​ 한가지 이상의 함수를 검사하면 정상적으로 동작을 안하네요.

제가 뭔가를 실수하고 있는 듯 한데 알려주시면 감사하겠습니다.

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
10년 전

함수 사용법이 틀렸어요.

 

 

Descriptionhttp://php.net/manual/en/function.preg-match.php#refsect1-function.preg-match-description"> ¶

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

 

 

"abcdef"; $pattern '/^def/'; preg_match($patternsubstr($subject,3), $matchesPREG_OFFSET_CAPTURE); print_r($matches); ?>

 

 

위와 같이 사용하는 거에요.

 

파라미터로 패턴, 문자열, Call by Address로 matches를 쓰고

리턴 값으로는 정수를 리턴하잖아요.

 

 

 

Return Valueshttp://php.net/manual/en/function.preg-match.php#refsect1-function.preg-match-returnvalues"> ¶

preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.

 

 

패턴이 있으면 1 , 없으면 0을 리턴한다는 뜻같은데.... false 아니면..

 

 

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

휴가
10년 전
감사합니다!!!!

댓글을 작성하려면 로그인이 필요합니다.

10년 전

사용법이 틀렸으니 안되죠

 

http://php.net/manual/en/function.preg-match.php">http://php.net/manual/en/function.preg-match.php

 

여기를 참고하세요 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

휴가
10년 전
제가 원하는 부분이 어떤 부분인지 짐작이 안가네요...
죄송하지만 힌드를 주실 수 있나요?

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인