preg_match 함수 질문드립니다.
본문
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
함수 사용법이 틀렸어요.
Description ¶
int preg_match
( string
$pattern
, string $subject
[, array &$matches
[, int $flags
= 0
[, int $offset
= 0
]]] )
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>
위와 같이 사용하는 거에요.
파라미터로 패턴, 문자열, Call by Address로 matches를 쓰고
리턴 값으로는 정수를 리턴하잖아요.
Return Values ¶
preg_match() returns 1 if the pattern
matches given subject
, 0 if it does not, or FALSE
if an error occurred.
패턴이 있으면 1 , 없으면 0을 리턴한다는 뜻같은데.... false 아니면..
답변을 작성하시기 전에 로그인 해주세요.