iframe 내용만 뽑아오기
본문
아래와 같이 iframe 코드가 2개 내용에 들어 있습니다.
첫번재 iframe만 뽑아오고 싶습니다.
조언 좀 부탁드립니다.
/iframe width="1280" height="720" src="https://www.youtube.com/embed/9L_tmU81tDc" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe/
/iframe width="1280" height="720" src="https://www.youtube.com/embed/9L_tmU81tDc" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe/
답변 1
만약 iframe 이 저렇게 순서대로 고정되서 출력한다고 치면 간단하게
$iframe_ex = explode('<iframe width="1280" height="720" src="', $content);
$iframe_ex = explode('" frameborder', $iframe_ex[1]);
echo $iframe_ex[0]; // 실질적으로 주소가 출력됨
이정도면 될것같고..
preg_match_all 은 정규식을 사용하셔서 하실 수 있습니다.
$pattern ='/(src=|href=)(\'|\")?([^<>\s\'\"]*)(\'|\"|\s|)/i';
preg_match_all( $pattern, $subject, $matches );
print_r($matches) 하셔서 원하는 곳을 출력하시면됩니다.