验证通知:“;在表“中看到的起始标记DIV;


Validation notice: "Start tag DIV seen in table"

我在运行验证时遇到以下错误:"在表中看到的启动标记div",导致"在上次错误后无法恢复。任何进一步的错误都将被忽略"。

<div class="post">
    <table>
        <?php
        $dir   = 'img/';
        $filetype = '*.*';
        $allow = array('jpg');
        $files = glob($dir.$filetype);
        $newest_images_first = true;
        $files = array_reverse($files);
        $i=0;
        $open = opendir($dir);      
        while (($file=readdir($open))!==false) {$ext=str_replace('.', '', strrchr($file, '.'));if (in_array($ext, $allow)) $list[$i++]=$file; }
        $perPage= 20;
        $total=count($list);
        $pages=ceil($total/$perPage);
        $thisPage=isset($_GET['pg'])?$_GET['pg']-1:0;
        $start=$thisPage*$perPage;
        $pageNumber= $thisPage+1;
        $perRow= 1;
        $imgCnt=0;
        $imgCnt+=1;
        for ($i=$start;$i<$start+$perPage;$i++) 
        { // <---------- this opens element
            echo '<div class="item">';  // <----------- this div doesn't open!!
                // Preloader
                echo '<div class="preloader"></div>';
                if (isset($list[$i])) {
                  echo '<figure>';
                   echo '<div class="photo">';
                    $exif = exif_read_data($files[$i], 0, true);
                    error_reporting(E_ERROR | E_PARSE);
                    $title = substr($files[$i],strlen($dir),strrpos($files[$i], '.')-strlen($dir));
                    $title = str_replace( array( '%', '_'), " ", $title);
                    $title = substr($title, 5);
                    $title = str_replace( array('', '_'), "", $title);
                    $imgname = $files[$i]; 
                    echo '<img src="'.$imgname.'" alt="blahblah '.$title.'" onLoad="this.width*=0.6;imgLoaded(this);" onError="this.onerror=null;this.src="bundles/blank.svg";">';
                  echo '</div>'; // .photo
                  echo '<figcaption>';                  
                  $title = preg_replace('/''([^'']+)''/', '<em>$1</em>', $title);
                  echo '<h2>'."". $title .'</h2>';
                  echo "<p>".$exif['IFD0']['ImageDescription']."</p>";
                  echo '</figcaption>';     
                 echo '</figure>';          
                            }
                            else {
                            echo "<td></td>";
                            }
                    if ($imgCnt%$perRow==0) echo "</tr><tr>";
                    echo '</div>'; // .item
                    }
                    closedir($open);
                    ?>
                    </table>        
                </div> <!-- post -->

我尝试了很多方法,但都找不到解决办法。你知道发生了什么事吗?

div标记可能不是表的直接子级,但可以在td标记中使用。错误消息误导了我"表内的div标记"。它可能是"内在的",只是不是一个直接的孩子。

<!DOCTYPE html>
<html>
<head>
  <title>Test</title>
</head>
<body>
<table>
   <div>DIV is not allowed here</div>
   <caption>  This it the Caption
          <div>This is a caption div -- why?</div>
   </caption>
     <tr>  <!-- tr Row 1 may not contain text.  -->
       <td> Col 1 Stuff goes here.</td>
       <td> Col 2 here.</td>
     </tr>
     <tr>
       <td>Col 1 of Row 2 is here.</td>
       <td>Col 2 Row 2
          <div>Sub part A</div>
          <div>Sub part B</div>
          <div>Sub part C</div>
       </td>
     </tr>
</body>
</html>

给出错误-错误:表中出现启动标记div。从第8行第8列开始;至第9行第8列

↩↩↩DIV是

致命错误:无法在上次错误后恢复。任何进一步的错误都将被忽略。

删除第8行并添加注释后,错误将消失。第13行显示了另一个类似的错误-tr不能直接包含文本。现在给出验证错误-错误:表中的非空格字符放置错误。这句话的措辞类似,imho,具有误导性。

为什么不在表中使用tr和td?table标记中的div标记不正确。