1

私はphpの新しい学習者です。YouTube ビデオの URL から埋め込み情報を取得しようとしています。私はもともとこのサイトのコードに従っていましたが、残念ながら作成者は実際のコードへのアクセスを提供していません。

埋め込まれたビデオ コードを取得できるように、php 変数の値を抽出するのが困難です。

htmlentities エコーがこのエラーを返していますsyntax error, unexpected T_CONSTANT_ENCAPSED_STRING

ソース:サイト

<html>
    <form method="post" action="">
    URL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" value="<?php $vari ?>" name="yurl"> <!--$vari-->
    <br>
    <br>
    Height:&nbsp;
    <input type="text" value="<?php $hth ?>" name="yheight"> <!--$hth-->
    <br>
    <br>
    Width:&nbsp;&nbsp;
    <input type="text" value="<?php $wdth ?>" name="ywidth"> <!--$wdth-->
    <br>
    <br>
    Autoplay:&nbsp;
    <input type="checkbox" value="<?php $auto1; $auto2; ?>" name="yautop">  <!--$auto1 $auto2-->
    <br>
    <br>
    <input type="submit" value="Generate Embed Code" name="ysubmit">
    </form>
</html>

YouTube の URL 情報を取得するための PHP コード

<?php
$vari ='';
$step1 =explode ('v=', $vari);
$step2 =explode ('&amp;',$step1[1]);

$auto1='?autoplay=1';

$auto2='&autoplay=1';


//Iframe code with autoplay
echo htmlentities ('<iframe src="http://www.youtube.com/embed/'.$step2[0].$auto1'"
frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>';

//embed code with autoplay
echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'"
type="application/x-shockwave-flash" src="http://www.youtube.com/v/'.$step2[0].$auto2'"
wmode="transparent" embed="" /></embed>');
?>
4

3 に答える 3

2

両方のエコー ブロックの(.)$step2[0].$auto2に連結演算子がありません。$step2[0].$auto1

echo htmlentities (...)

そのはず:

 echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'"type="application/x-shockwave-flash" src="http://www.youtube.com/v/"'.$step2[0].$auto2.'"wmode="transparent" embed="" /></embed>');

また、自動再生を使用する Iframe コードで、スペルが間違ってい$auto1ます。エラーは発生しませんが、正しく動作しません。

于 2012-07-11T06:02:36.027 に答える
1

以下のコードを試してください...動作するはずです

<?php
$vari ='';

if($_POST)
{
    $vari       = $_POST['yurl'];
    $hth        = $_POST['yheight'];
    $wdth       = $_POST['ywidth'];
    $is_auto    =   0;

    $step1 =explode ('v=', $vari);
    $step2 =explode ('&amp;',$step1[1]);

    if(isset($_POST['yautop'] ))
    {
        if($_POST['yautop'] == 1)
            $is_auto    =   1;
    }
    $auto1  = '?autoplay='.$is_auto;
    $auto2  = '&autoplay='.$is_auto;

//Iframe code with autoplay

echo htmlentities ('<iframe src="http://ww.youtube.com/embed/'.$step2[0].$auto1.'" frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>');

//embed code with autoplay
echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'" type="application/x-shockwave-flash" src="http://www.youtube.com/v/'.$step2[0].$auto2.'" wmode="transparent" embed="" /></embed>');
}
?>

問題は

  1. 連結演算子 (.) がありませんでした
  2. 「$atuo1」の変数名が無効でした
  3. ポストブロックがありませんでした。

アップデート

iframe 行を次の行に置き換えてください (注: URL に「w」が 1 つ欠けていて、「ww」でした)

echo htmlentities ('<iframe src="http://www.youtube.com/embed/'.$step2[0].$auto1.'" frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>');
于 2012-07-11T06:12:55.017 に答える