채택완료

preg_match 를 통해 정규식 사용해서 문자열을 찾는데요

2018-09-20 (목) 14:14:03 2,932

내용 중 href="xxxxxx" 주소를 추출하려고 아래와 같이 정규식을 만들었습니다.

<link rel="alternate" type="application/xml+oembed" href="https://www.aaa.co.kr/plugins/post/oembed.xml/?url=https%3A%2F%2Fwww.tibrao.co.kr%2Fdy%2Fposting%2F13259426435161" title="&#vbd1;&#xcfc;&#xc601; - #cosko &#x135;&#xb30f;" />

preg_match('/oembed"\shref=(.*?)title/', $snoopy->results, $text);
echo $text[1];

문서 상에

oembed 이라는 문자열이 2개 있는데 원하는 주소가 첫번째에 있어서 추출 성공하였는데요

preg_match 시작점을  xml+oembed" href=     xml+ 추가해서 진행하려는데요

어떻게 표시해야 할지 ??

preg_match('/xml+oembed"\shref=(.*?)title/', $snoopy->results, $text);

매칭 되는것이 없는 듯...아무것도 출력되지 않아서..

|

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
2018-09-21 (금) 12:11:00

href 안에 있는 내용을 추출하려고 하는거죠?

preg_match('~<link[^>]+href="([^"]+)~is', $snoopy->results, $text);

이렇게 하시면 됩니다.

답변에 대한 댓글 1개

감사합니다...

link와 href 되어있는 것들이 많아서.

xml+oembed 문자열 이후에 오는 href 주소를 추출하려고 합니다.
2018-09-22 (토) 15:26:42

xml\+oembed[^>]+href="([^"]+)

그럼 이렇게 하세요

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