duanji1924 2013-08-05 00:22
浏览 54
已采纳

使用时的差异<? 和<?php [复制]

This question already has an answer here:

I've been wondering what's the difference of using <? and <?php. For example in this lines of code.

function getWallboard()
{

    $.ajax({
    type: "POST",
url: "quality_control/qc_ajax.php",
data: "action=get_queue_totals&wallboard=<? echo $_REQUEST['wallboard'];?>",
success: function(msg){
$("#queue_nav").fadeIn("fast");
        $("#queue_nav").html(msg);
    }
});        

    $.ajax({
    type: "POST",
url: "quality_control/qc_ajax.php",
data: "action=getQCWallboard&qctype=<?php echo $_REQUEST['qctype'];?>&wallboard=<? echo $_REQUEST['wallboard'];?>",
success: function(msg){
$("#wallboard").fadeIn("fast");
        $("#wallboard").html(msg);
    }
});
}

I've been getting error for some instance. Like If I change <? to <?php or <?php to <?, some of my code block doesn't work.

This is my first post. I hope I can get ideas about the use of this.

</div>
  • 写回答

1条回答 默认 最新

  • 普通网友 2013-08-05 00:25
    关注

    The first (<?php) is a safe open and close tag variation, the second is the so called short-open tag (<?, <?=). The second one is not always available, use the first option if it's possible. In PHP 5.4, the <? is always available regardless the settings.

    <?php is used to write an actual PHP page. However, <? ?> are generally used within HTML code to make easier to read.

    EDIT

    MyFile.php

    <?php
    class MyClass {
        public function MyFunction(){
            $Title = 'my title';
            $Paragraph = 'paragraph';
    
            include 'MyTemplate.php';
        }
    }
    ?>
    

    MyTemplate.php

    <!DOCTYPE HTML>
    <html>
        <head>
            <title>This is <? echo $Title; ?></title>
        </head>
        <body>
            <p>Hello - I am a <?= $Paragraph; ?> !</p>
        </body>
    </html>
    

    However, you should always use <?php ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错