Question:
Many developers ask: “Can I use short tags (<? and <?=) in my PHP code instead of the normal <?php?”
Answer:
1. Types of Short Tags
<? ... ?>→ Old “short open tag.”<?= ... ?>→ Short echo tag, used to quickly print values.
Example:
<?= "Hello World"; ?>
This works the same as:
<?php echo "Hello World"; ?>
2. Availability
- The short echo tag (
<?=) is always enabled in PHP 5.4 and above. Safe to use. - The short open tag (
<?) depends on theshort_open_tagsetting inphp.ini. If disabled, your code may break.
3. Portability Issues
If you move your script to another server where short_open_tag is turned off, your code may stop working. That’s why most frameworks recommend avoiding it.
4. Best Practice
- Always use
<?php ... ?>→ safest and most reliable. - You may safely use
<?= ... ?>for echo/print → modern and supported everywhere. - Avoid
<?→ may cause problems.
5. Example (Recommended Way)
<?php $name = "Ucartz"; ?> <p>Welcome, <?= $name ?>!</p>
Summary:
- Use
<?php→ safest. - Use
<?=→ safe and recommended for echo. - Avoid
<?→ may cause issues on some servers.
