regex 정규식 질문 드립니다

regex 정규식 질문 드립니다

QA

regex 정규식 질문 드립니다

답변 3

본문

!시작!
<img     src="https://www.naver.com/1.jpg" data-src="/data/daumeditor10/231115/thumbnail3/46321717000154390.jpeg" class="txc-image" width="760" style="""" / name="target_resize_image[]" onclick="org_win(this);" style="cursor:pointer;" >
!끝!

 

타사이트에서 예를 들어 위와 같은 내용을 가져오려하는데

    src="https://www.naver.com/1.jpg" data-

이 부분을 제외하고

<img     src="/data/daumeditor10/231115/thumbnail3/46321717000154390.jpeg" class="txc-image" width="760" style="""" / name="target_resize_image[]" onclick="org_win(this);" style="cursor:pointer;" >

 

이런식으로 가져올순 없나요?

어떠한 정규식을 짜야하는지 모르겠습니다

이 질문에 댓글 쓰기 :

답변 3

안녕하세요.

원하시는 내용이 정확히 맞는지 모르겠지만 참고를 해보시겠어요~


<?php
$html = '!시작!<img src="https://www.naver.com/1.jpg" data-src="/data/daumeditor10/231115/thumbnail3/46321717000154390.jpeg" class="txc-image" width="760" style="""" / name="target_resize_image[]" onclick="org_win(this);" style="cursor:pointer;" >!끝!';
$pattern = '/<img[^>]*\ssrc=["\']([^"\']*)["\'][^>]*>/';
preg_match($pattern, $html, $matches);
if (isset($matches[1])) {
    $imageUrl = $matches[1];
    echo $imageUrl;
} else {
    echo "이미지 URL을 찾을 수 없습니다.";
}
?>
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로