代码未验证,可能是不正确的标记?

时间:2014-08-06 19:56:57

标签: php html5 validation w3c-validation

我遇到问题使用文档类型为<!doctype html>的W3C验证此代码,据我所知,这是HTML5文档类型。

     <?php 
   echo "<img src='uploads/picture01.jpg?".filemtime ('uploads/picture01.jpg')."' class='img' alt='Bass Clef Photography Demo Picture One'/>";
   echo "<img src='uploads/picture02.jpg?".filemtime ('uploads/picture02.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Two'/>";
   echo "<img src='uploads/picture03.jpg?".filemtime ('uploads/picture03.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Three'/>";
   echo "<img src='uploads/picture04.jpg?".filemtime ('uploads/picture04.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Four'/>";
   echo "<img src='uploads/picture05.jpg?".filemtime ('uploads/picture05.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Five'/>";
   echo "<img src='uploads/picture06.jpg?".filemtime ('uploads/picture06.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Six'/>";
   echo "<img src='uploads/picture07.jpg?".filemtime ('uploads/picture07.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Seven'/>";
   echo "<img src='uploads/picture08.jpg?".filemtime ('uploads/picture08.jpg')."' class='img' alt='Bass Clef Photography Demo Picture Eight'/>";

   ?>

我为每一行获得的错误是;

enter image description here

生成代码,

<img src='uploads/picture01.jpg?1405031988' class='img' alt='Bass Clef Photography Demo Picture One'/>
<img src='uploads/picture02.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Two'/>
<img src='uploads/picture03.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Three'/>
<img src='uploads/picture04.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Four'/>
<img src='uploads/picture05.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Five'/>
<img src='uploads/picture06.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Six'/>
<img src='uploads/picture07.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Seven'/>
<img src='uploads/picture08.jpg?1397567043' class='img' alt='Bass Clef Photography Demo Picture Eight'/> 

NB。我已将文件时间附加到每个图像以停止浏览器缓存图像。

2 个答案:

答案 0 :(得分:2)

您在图片名称后缺少结束'

<?php 
   echo "<img src='uploads/picture01.jpg?" .filemtime ('uploads/picture01.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture One'/>";
   echo "<img src='uploads/picture02.jpg?" .filemtime ('uploads/picture02.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Two'/>";
   echo "<img src='uploads/picture03.jpg?" .filemtime ('uploads/picture03.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Three'/>";
   echo "<img src='uploads/picture04.jpg?" .filemtime ('uploads/picture04.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Four'/>";
   echo "<img src='uploads/picture05.jpg?" .filemtime ('uploads/picture05.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Five'/>";
   echo "<img src='uploads/picture06.jpg?" .filemtime ('uploads/picture06.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Six'/>";
   echo "<img src='uploads/picture07.jpg?" .filemtime ('uploads/picture07.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Seven'/>";
   echo "<img src='uploads/picture08.jpg?" .filemtime ('uploads/picture08.jpg') . "' class='img' alt='Bass Clef Photography Demo Picture Eight'/>";

   ?>

编辑:交换双引号和单引号

<?php 
   echo '<img src="uploads/picture01.jpg?' .filemtime ('uploads/picture01.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture One" />';
   echo '<img src="uploads/picture02.jpg?' .filemtime ('uploads/picture02.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Two" />';
   echo '<img src="uploads/picture03.jpg?' .filemtime ('uploads/picture03.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Three" />';
   echo '<img src="uploads/picture04.jpg?' .filemtime ('uploads/picture04.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Four" />';
   echo '<img src="uploads/picture05.jpg?' .filemtime ('uploads/picture05.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Five" />';
   echo '<img src="uploads/picture06.jpg?' .filemtime ('uploads/picture06.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Six" />';
   echo '<img src="uploads/picture07.jpg?' .filemtime ('uploads/picture07.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Seven" />';
   echo '<img src="uploads/picture08.jpg?' .filemtime ('uploads/picture08.jpg') . '" class="img" alt="Bass Clef Photography Demo Picture Eight" />';

   ?>

答案 1 :(得分:1)

W3C Markup Validation Service检查文档是否使用有效的 HTML

您收到错误是因为您尝试验证包含 PHP 的文档:验证程序尝试将其解释为HTML。

解决方案:验证生成的文档(在PH​​P运行之后)。您会看到您的代码段是有效的HTML5。