regex 정규식 질문 드립니다

regex 정규식 질문 드립니다

QA

regex 정규식 질문 드립니다

본문

!시작!
<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을 찾을 수 없습니다.";
}
?>
답변을 작성하시기 전에 로그인 해주세요.
전체 125,873 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT