YoutubeのビデオURLから変数を抽出して埋め込みコードを取得しようとしています。これまでのところ、埋め込みの古い方法は機能していますが、Iframeの方法はありません。URLの「watch?v =」の後に11文字しかない場合、Iframeは正常に機能しますが、URLに「&feature=g」が11文字含まれている場合に問題が発生します。「&feature = g」を取り除く解決策はありますか、それとももっと良い方法がありますか?第二に、それほど重要ではありませんが、自動再生をクリックするたびに、ビデオでautplayの結果が得られませんか?これが私の例です
埋め込みコードを取得するためのPHP
<?php
$vari ='';
if($_POST)
{
$vari = $_POST['yurl'];
$hth = 300; //$_POST['yheight'];
$wdth = 500; //$_POST['ywidth'];
$is_auto = 0;
$step1 =explode ('v=', $vari);
$step2 =explode ('&',$step1[1]);
if(isset($_POST['yautop'] ))
{
if($_POST['yautop'] == 1)
$is_auto = 1;
}
$auto1 = '?autoplay='.$is_auto;
$auto2 = '&autoplay='.$is_auto;
//Iframe code
echo ('<iframe src="http://www.youtube.com/embed/'.$step2[0].'" frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>');
//Old way to embed code
echo ('<embed width="'.$wdth.'" height="'.$hth.'" type="application/x-shockwave-flash" src="http://www.youtube.com/v/'.$step2[0].'" wmode="transparent" embed="" /></embed>');
}
?>
html
<html>
<form method="post" action="">
URL:
<input type="text" value="<?php $vari ?>" name="yurl"> <!--$vari-->
<br>
<br>
Autoplay:
<input type="checkbox" value="<?php $auto1; $auto2; ?>" name="yautop"> <!--$auto1 $auto2-->
<br>
<input type="submit" value="Generate Embed Code" name="ysubmit">
<br>
</form>
</html>