anisgazig at gmail dot com ¶8 months ago
If you want your file to be interpreted as php then your file must start and end with <?php and ?> and everything outside of that is ignored by the php parser.
<?php
php code..php code..?>
hellow..//normal test but ignred by php parser
Three types of tag are available in php
1.normal tag(<?php ?>)
2.short echo tag(<?= ?>)
3.short tag(<? ?>)
short tag are bydefault available but can be disabled by short_open_tag = Off and also disabled bydefault if php will built with --disabe--short--tags()
As short tag can be disabled so only use the normal and short echo tag.
If your file only have php code then do not use closing tag.
<?php
but if you are embedding php with html then enclose php code with opening and closing tag.
<html>
<head>
</head>
<body>
<?php
?>
</body>
</html>
If you want to just print single text or something ,you should use shorthand version .<?= $var ?>
But if you want to process something, you should use normal tag.
<?php
?>
If you embedded php with html and single line, do not need to use semicolon
<html>
<head>
<body>
<?= $var ?>
</body>
</head>
</html>
but if you have multiple line, then use semicolon.
<?php
?>
anisgazig at gmail dot com ¶8 months ago
There is no defference between normal(<?php ?>) and short echo tag() but without uses of comments.
example:
<h1>Normal tag with c++ style oneline comment: <?php ?> breaks php mode and return html mode </h1>
<h1>html code after (normal tag)<?php ?> breaks php mode and return html mode</h1>
but in short echo tag
<h1>html code after (short echo tag)<?php ?> breaks php mode and does not return html mode</h1>
Same rules are applied within # and /**/ style comments.
admin at bharatt dot com dot np ¶1 year ago
You may want to know that removing semicolon is optional sometime but need to know the condition when it can be removed and when it can't be.
-------------------------------------------------------------------------
// Example 1: PHP script with closing tag at the end.
<?php
mysqli_close( $db )
?>
// Example 2: PHP script without closing tag at the end.
<?php
mysqli_close( $db )
-----------------------------------------------------------------------