🌐
PHP
php.net › manual › en › language.basic-syntax.phptags.php
PHP: PHP tags - Manual
When PHP processes a file, it recognizes the opening and closing tags, <?php and ?>, to define the boundaries of PHP code execution.
🌐
w3resource
w3resource.com › php › syntax › syntax.php
PHP Syntax and Tags - w3resource
August 19, 2022 - Here is the list of tags. ... The default syntax starts with "<? php" and ends with "?>".
🌐
W3Schools
w3schools.com › php › php_syntax.asp
PHP Syntax
addcslashes() addslashes() bin2hex() chop() chr() chunk_split() convert_cyr_string() convert_uudecode() convert_uuencode() count_chars() crc32() crypt() echo() explode() fprint() get_html_translation_table() hebrev() hebrevc() hex2bin() html_entity_decode() htmlentities() htmlspecialchars_decode() htmlspecialchars() implode() join() lcfirst() levenshtein() localeconv() ltrim() md5() md5_file() metaphone() money_format() nl_langinfo() nl2br() number_format() ord() parse_str() print() printf() quoted_printable_decode() quoted_printable_encode() quotemeta() rtrim() setlocale() sha1() sha1_file()
🌐
Phpforkids
phpforkids.com › php › php-syntax-opening-closing-tags.php
Opening And Closing PHP Tags - PHP Syntax - PHP Tutorial - PHP For Kids.com
All code written in PHP must be identified as PHP code. A set of tags are used to mark the beginning and end of a block of code, in between which any amount of code can be written.
🌐
TutorialsPoint
tutorialspoint.com › php-tags
PHP Tags
September 19, 2020 - A PHP code script is a text file having .php extension and is stored on web server. The PHP parser on server looks for special sequence of characters <?php and ?>. These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser.
🌐
Php5-tutorial
php5-tutorial.com › basics › php-tags
PHP tags - The complete PHP tutorial
In the last chapter, we used those magic PHP tags. You may save your files with the .php extension, but that's not enough. Sure, when you use the appropriate extension, as defined in the config file of the webserver, PHP will look at the file. But only the stuff between the PHP tags are actually ...
🌐
Exakat
php-dictionary.readthedocs.io › en › latest › dictionary › php-tag.ini.html
PHP Tags — PHP Dictionary 1.0.145 documentation
February 18, 2026 - <?php // This is the classic PHP tag ?> <? // This is the short PHP tag ?><?= "Hello world"; // This is the short echo PHP tag ?>
🌐
Docker Hub
hub.docker.com › _ › php › tags
php Tags | Docker Hub
While designed for web development, the PHP scripting language also provides general-purpose use. Languages & frameworks · OverviewTags · Sort by · Newest · ​ · ​ · ​ · TAG · 8.4.19-zts-trixie · Last pushed 6 days by doijanky · docker pull php:8.4.19-zts-trixieCopy ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-basic-syntax
PHP Syntax - GeeksforGeeks
September 5, 2024 - PHP code is executed between PHP tags, allowing the integration of PHP code within HTML. The most common PHP tag is <?php ... ?>, which is used to enclose PHP code.
🌐
FlatCoding
flatcoding.com › home › php syntax: standard tags, echo, and short tags
PHP Syntax: Standard Tags, Echo, and Short Tags - FlatCoding
April 15, 2025 - PHP syntax and tags are keys in PHP scripting. It includes standard open/close tags, short tags, and shorthand tags in coding. For Example...
🌐
DEV Community
dev.to › hurayraiit › php-tags-3c0e
PHP Tags - DEV Community
October 22, 2024 - In PHP there are several types of tags that can be used to embed PHP code within HTML or other... Tagged with php, beginners, programming, tutorial.
🌐
Frontend Masters
frontendmasters.com › courses › php › php-tags
PHP Tags - PHP Basics | Frontend Masters
Maximiliano creates a simple PHP file and demonstrates PHP tags. These tags contain the executed PHP code. Anything outside a PHP tag is considered string output. The closing tag can be omitted when a …
🌐
SitePoint
sitepoint.com › blog › programming › should you close php tags? the debate continues…
Should You Close PHP Tags? The Debate Continues... — SitePoint
February 13, 2024 - The primary reason for this recommendation is to prevent the accidental inclusion of whitespace characters after the closing PHP tag. These characters can cause unwanted output, errors, or header redirection issues. It’s a common mistake that can be easily avoided by simply omitting the closing tag.
🌐
PHP
pear.php.net › manual › en › standards.tags.php
PHP Code Tags - Manual - PEAR
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand.
Top answer
1 of 8
242

History

Before the misinformation train goes too far out of the station, there are a bunch of things you need to understand about PHP short tags.

The primary issue with PHP's short tags is that XML managed to choose a tag (<?) that was already used by PHP.

With the option enabled, you weren't able to raw output the xml declaration without getting syntax errors:

<?xml version="1.0" encoding="UTF-8" ?>

This is a big issue when you consider how common XML parsing and management is.

What about <?=?

Although <? causes conflicts with xml, <?= does not. Unfortunately, the options to toggle it on and off were tied to short_open_tag, which meant that to get the benefit of the short echo tag (<?=), you had to deal with the issues of the short open tag (<?). The issues associated with the short open tag were much greater than the benefits from the short echo tag, so you'll find a million and a half recommendations to turn short_open_tag off, which you should.

With PHP 5.4, however the short echo tag has been re-enabled separate from the short_open_tag option. I see this as a direct endorsement of the convenience of <?=, as there's nothing fundamentally wrong with it in and of itself.

The problem is that you can't guarantee that you'll have <?= if you're trying to write code that could work in a wider range of PHP versions.

ok, so now that that's all out of the way

Should you use <?=?

2 of 8
32

Dusting off my PHP hat

I'd definitely favor the use of <?= $someVar ?> over the more verbose echo (simply personal preference). The only downside AFAIK is for users who are running pre-5.4.0, in which case short_open_tag must be enabled in php.ini.

Now having said that, if your project isn't OS, then it's a moot point. If it is, I'd either document the fact that short_open_tags must be enabled, or use the more portable of the two solutions.

🌐
Quora
quora.com › What-are-the-PHP-tags-and-how-are-they-used
What are the PHP tags, and how are they used? - Quora
Answer: 1. Short Tags: [code ] [/code] or [code ] [/code]Example:phpCopy code[code ] [/code] 2. Long Tags: [code ] [/code]Example:phpCopy code[code ] [/code] In the short tags, [code ]
Top answer
1 of 2
66

This is well documented. From the PHP Manual:

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Omitting the closing tag helps you prevent accidental whitespace or newlines from being added to the end of the file.

2 of 2
20

That's a core PHP feature: unlike other languages, you need to tag PHP code with a special tag (normally <?php) because everything else is considered literal output:

This is not PHP
<?php

echo 'This is PHP' . PHP_EOL;

?>
This is not PHP either
D:\tmp>php test.php
This is not PHP
This is PHP
This is not PHP either

Although the manual mentions HTML, PHP doesn't really know/care what content-type is outside its tags.

If you forget to close a PHP block when further stuff follows you normally get a syntax error:

This is not PHP
<?php

echo 'This is PHP' . PHP_EOL;

This is not PHP either
D:\tmp>php test.php
PHP Parse error:  syntax error, unexpected 'is' (T_STRING) in D:\tmp\borrame.php on line 6

Blank lines are a sort of special case because they are valid and almost invisible in almost all languages (PHP, HTML, CSS, JavaScript...) so they often unnoticed.

Once you've removed the ?> tag, your literal blank lines have disappeared from the script output because they've become part of the PHP code (and, as such, they've started to get ignored).

Of course, blank lines are ignored by PHP but not necessarily by whatever you are generating which, as I said, does not need to be HTML: it can be a picture, a PDF document, an Excel spreadsheet. Bogus white lines can be easily avoided by not closing the last PHP block when it's the last part of the file.