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