0

首先,我的问题可能不清楚。我会试着解释一下。

这是我的html

<div class="left"><?php print $search_box; ?><?php if (!empty($logo)): ?><a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" id="logo" width="243" height="62" /></a><?php endif; ?><?php if (!empty($site_name)): ?><div id='site-name'><strong><a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><?php print $site_name; ?></a></strong></div><?php endif; ?><?php if (!empty($site_slogan)): ?><div id='site-slogan'><?php print $site_slogan; ?></div><?php endif; ?></div>

看起来丑陋且难以调试,对吧?

所以我尝试缩进并添加换行符。但是,它会在某些浏览器上失败,可能是 IE6。结果变了。那么,我应该怎么做,我应该使用其他文档类型吗?

目前,我正在使用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4

1 回答 1

1

你也可以这样写:

<div class="left">
  <?php print $search_box; ?>
    <?php if (!empty($logo)) { ?>
    <a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home">
      <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" id="logo" width="243" height="62" />
    </a>
  <?php } ?>

  <?php if (!empty($site_name)) { ?>
    <div id='site-name'>
      <strong>
      <a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><?php print $site_name; ?></a>
      </strong>
    </div>
  <?php } ?>

  <?php if (!empty($site_slogan)) { ?>
    <div id='site-slogan'><?php print $site_slogan; ?></div>
  <?php } ?>
</div>

这在大多数情况下应该可以工作,或者您可以使用php heredoc 语法来正常回显 html 内容。

于 2010-01-26T06:22:59.353 回答