首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用echo创建amp-html代码时查找PHP语法错误时遇到问题

使用echo创建amp-html代码时查找PHP语法错误时遇到问题
EN

Stack Overflow用户
提问于 2018-09-04 02:27:22
回答 2查看 99关注 0票数 1

我正在尝试使用PHP回显一些amp-html代码

<?php
echo "<section>";
echo "<h3>$title[$i]</h3>";
echo "<amp-video controls width="560" height="315" layout="responsive">";
echo "<source src="https: //example.com/videos/";
    echo $filename[$i];
    echo "_HD.mp4 type="video / mp4 / > ";
    echo " < sourcesrc = "https://example.com/videos/";
    echo $filename[$i];
    echo '"__HD.webm" type="video/webm"/>';
    echo "<div fallback><p>This browser does not support the video element.</p></div>";
    echo "</amp-video>";
    echo "</section>";
?>

我找不到一个语法错误,我遗漏了什么?有比使用echo更简单的方法吗?

更新:我已经根据建议编辑了代码,但仍然出现了一个空白页面:以下是完整的代码:

<?php
        // Create connection
        $con=mysqli_connect("localhost","xx","xxxx","xxxx");

       // Check connection
    if (mysqli_connect_errno($con)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    //Get number of rows

$sql="SELECT id,title,filename FROM videos";

    $result=mysqli_query($con, $sql);
    $i=1;
    while($row=mysqli_fetch_assoc($result))
    {
        $id[$i] = $row['id'];
        $title[$i] = $row['title'];
        $filename[$i] = $row['filename'];
        $i++;
    }
    // Loop through the results from the database

    for ($i = 1; $i <=count($id); $i++)
    {
?>

<section>
    <h3><?php echo $title[$i];?></h3>
    <amp-video controls width="560" height="315" layout="responsive">
        <source src="https: //example.com/videos/<?php echo $filename[$i];?>_HD.mp4" type="video/mp4" />
        <source src="https://example.com/videos/<?php echo $filename[$i];?>__HD.webm" type="video/webm" />
        <div fallback><p>This browser does not support the video element.</p></div>
    </amp-video>
</section>
}
</amp-accordion>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-04 02:58:29

由于您的代码中实际的PHP输出如此之少,放弃PHP来输出HTML可能会更容易和更具可读性。

        // Create connection
        $con=mysqli_connect("localhost","xx","xxxx","xxxx");

       // Check connection
    if (mysqli_connect_errno($con)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    //Get number of rows

$sql="SELECT id,title,filename FROM videos";

    $result=mysqli_query($con, $sql);
    while($row=mysqli_fetch_assoc($result)) {
?>

<section>
    <h3><?php echo $row['title']; ?></h3>
    <amp-video controls width="560" height="315" layout="responsive">
        <source src="https: //example.com/videos/<?php echo $row['filename']; ?>_HD.mp4" type="video/mp4" />
        <source src="https://example.com/videos/<?php echo $row['filename']; ?>__HD.webm" type="video/webm" />
        <div fallback><p>This browser does not support the video element.</p></div>
    </amp-video>
</section>
<?php
    }  // end of while
?>
</amp-accordion>
<?php
票数 0
EN

Stack Overflow用户

发布于 2018-09-04 02:52:11

问题确实出在语法的使用上。您应该尝试做的是,当您回显html时使用单引号,以及您可以在html中添加的任何其他内容,您可以使用双引号。

  <?php
echo '<section>';
echo '<h3>$title[$i]</h3>';
echo '<amp-video controls width="560" height="315" layout="responsive">';
echo '<source src="https://example.com/videos/'.$filename[$i].'_HD.mp4" type="video / mp4 / >"';
    echo '<source src="https://example.com/videos/'.$filename[$i].'__HD.webm" type="video/webm"/>"';
    echo '<div fallback><p>This browser does not support the video element.</p></div>';
    echo '</amp-video>';
    echo '</section>';
?>

这样就更容易发现语法错误,因为页面要么显示它必须显示的内容,要么显示代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52154718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档