表題の「iframeからユーチューブの動画IDを取得」したいのですが、教えて頂けますでしょうか。
現在、下のようにコードを組んでるのですが、
ユーチューブのiframeから、動画IDだけ取得することは可能でしょうか。
恐れ入ります、よろしくお願い申し上げます。
<?php
$iframe = '';
$src = '';
$youtube_v_id = '';
// get oEmbed
//「https://youtu.be/q7GFtKuEQik」を入力時
$iframe = get_sub_field('mv-content-url');
/*
var_dump( $iframe ) ;
//string(137) "<iframe width="640" height="360" src="https://www.youtube.com/embed/q7GFtKuEQik?feature=oembed" frameborder="0" allowfullscreen></iframe>"
*/
if($iframe):
// use preg_match to find iframe src
preg_match('/src="(.+?)"/', $iframe, $matches);
$src = $matches[1];
$youtube_v_id = 'q7GFtKuEQik';//これを取得したい
endif;
?>