使用echo创建amp-html代码无法找到PHP语法错误

时间:2018-09-03 18:27:22

标签: php amp-html

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

public partial class PageEventsUC : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.PreRenderComplete += Page_PreRenderComplete;
    }

    private void Page_PreRenderComplete(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
}

我一直找不到语法错误,我缺少什么?有没有比使用echo更简单的方法??

更新: 我已经根据建议编辑了代码,但是仍然抛出空白页:这是完整的代码:

<?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>";
?>

2 个答案:

答案 0 :(得分:0)

问题确实是您使用的语法。您应该尝试做的是在对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>';
?>

这样,发现语法错误要容易得多,因为页面将显示必须显示的内容或显示代码。

答案 1 :(得分:0)

由于您的代码中实际的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