문자열에서 URL 추출함수 정규식
페이지 정보
작성자
본문
REGEX는 문제의 답입니다. Object Manipulator의 답변을 .. 누락 된 것은 "쉼표"를 제외하는 것이므로이 코드를 제외하고 3 개의 분리 된 URL을 출력으로 제공 할 수 있습니다.
$string = "The text you want to filter goes here. http://google.com, https://www.youtube.com/watch?v=K_m7NEDMrV0,https://instagram.com/hellow/";
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $string, $match);
echo "<pre>";
print_r($match[0]);
echo "</pre>";
출력은
Array
(
[0] => http://google.com
[1] => https://www.youtube.com/watch?v=K_m7NEDMrV0
[2] => https://instagram.com/hellow/
)
관련링크
댓글목록
등록된 댓글이 없습니다.