-1

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.

  • http://php.net/manual/en/language.basic-syntax.phptags.php: `PHP also allows for short tags and ?> (which are discouraged because they are only available if enabled with short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option. ` –  Aug 05 '13 at 00:25
  • 2
    @Akam LOOOL at `...which are discouraged...` the PHP manual is playing games with its users :D – Songo Aug 05 '13 at 00:28

1 Answers1

0

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 ?>

David Bélanger
  • 7,400
  • 4
  • 37
  • 55