简体   繁体   English

在php中关闭元素标签

[英]Closing element tags in php

I have just started to learn PHP from books and have come across something I don't understand. 我刚刚开始从书籍中学习PHP,并且遇到了一些我不了解的东西。 In the book they never close html tags is this correct practice or should they be closed? 在这本书中,他们从不关闭html标签,这是正确的做法还是应该将其关闭? Here is an example of the books content: 这是书籍内容的示例:

    <?php

        $cars = array('Dodge'=>'Viper','Chevrolet'=>'Camaro','Ford'=>'Mustang');
        echo '<dl><dt>Original Element Order:<dd>';
        foreach($cars as $key => $value){
            echo '&bull;', $key.' '.$value;
        }

    ?>

Could anyone tell me if this is correct and common practice? 谁能告诉我这是正确的常规做法吗? Thanks 谢谢

Some old books :). 一些旧书:)。 They definitely need to be closed. 他们肯定需要关闭。 You need to echo </dd></dt></dl> after the foreach loop. 您需要在foreach循环后回显</dd></dt></dl>

The end tags for the <dt> and <dd> elements are optional in HTML. <dt><dd>元素的结束标记在HTML中是可选的。 The missing </dl> is a problem though. 缺少的</dl>是一个问题。

Other issues with this fragment: 此片段的其他问题:

  • Using &bull; 使用&bull; for a list instead of list markup 用于列表而不是列表标记
  • Using something that looks like a <ul> (but is simulated with &bull; ) for key/value pairs 为键/值对使用看起来像<ul> (但用&bull;进行模拟)
  • Having a dl with only one dt in it. 只有一个dtdl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM