You are here

4PHP开始和结束标签

admin 的头像
Submitted by admin on 星期五, 2015-09-18 08:38

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

包含代码的文件,比如.module.inc文件,会使用PHP代码开始标签,如下所示:

 

<?php

...

 

Drupal中不能使用开始标签的简写形式“<?”

结束标签“?>”,在PHP中不是必须的,但是在Drupal的模块代码中,它是被禁止使用的。如果使用了PHP的结束标签,那么可能会带来一些潜在的问题。不过这也有例外情况,在Drupal的模板文件中,为了退出PHP并且回到HTML中,此时会使用结束标签,例如,在themes/bartik/templates/node.tpl.php中,就同时用到了PHP的开始、结束标签:

 

  <?php print render($title_prefix); ?>

  <?php if (!$page): ?>

    <h2<?php print $title_attributes; ?>>

      <a href="<?php print $node_url; ?>"><?php print $title; ?></a>

    </h2>

  <?php endif; ?>

  <?php print render($title_suffix); ?>


Drupal版本: