PHP에서 Gruber 's Regex를 사용한 URL 매칭
-
19-09-2019 - |
문제
Regex를 어떻게 언급합니까? 이 기사에서 PHP에서 preg_match와 함께 작업 하시겠습니까?
<?php
preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches);
print_r($matches);
?>
위의 코드를 사용하면 다음 오류가 발생합니다.
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash...
해결책
이 시도:
preg_match("#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#i", $text, $matches);
당신은 Regex Delimiters를 놓치고있었습니다 (보통 /
, 그러나 사용 #
URL에 더 편리하기 때문에 여기에서
제휴하지 않습니다 StackOverflow