<?php blabla.... ?> or <? blabla.... ?>

Good morning,

I was watching a php learning video, where the guy give some examples by writing the code without the word “php”, so like that :

<? blabla.... ?>  

Is that correct ? or we should write always the code like the following :

<?php blabla.... ?>

Thanks for your support.

I have been writing PHP for more than a decade (almost two, I believe) and developed the habit, right from the beginning, of not including the php in the tag.
The filename (extension actually) is enough of a clue to the server.

Of course, it is considered better form to be more explicit. But as a typical (ie lazy) developer I want the fewest keystrokes necessary.

1 Like

I have read that <?php blabla.... ?> is the safer option, as <? blabla.... ?> does not work on all servers - but that was in an old book and may no longer be accurate.


I have actually came across <? blabla.... ?> where it would not work on a server, found out the hard way after spending hours trying to figure out what was wrong (felt stupid when I figured it out). Anyways out of habit I just include php, it’s only three letters which shouldn’t be a problem even for the laziest programmers. :smile:


Thank you all for your reply, but I think that TechnoBear is right when she said :

and for that I asked the question. And about your comment Pepster :

[quote=“Pepster, post:4, topic:115717”]
Anyways out of habit I just include php, it’s only three letters which shouldn’t be a problem even for the laziest programmers.
[/quote] :smile: it is funny and I agree with you, but when you insert a lot of php codes in an html page, it will be counted, no ?

Anyways, your comments guy are always helpful…thanks again

the letter count of your source code should be the least concern of yours. if your code readability or indentation or program design sucks, code maintenance will be a hell lot of work.

I think I did not explain exactly what I mean. I was talking about the number of letters that you type, 4 instead of 1. Anyways, this will never bother me to type ?php, I just want to know if it is right to write it without “php” and got the anwer. But, as there is discussion about this point, I prefer to write always as I learn :

<?php blabla.... ?>


Still accurate. :slight_smile: Even the manual says it’s discouraged.


1 Like

Why does that matter? Why do we care about character count of a PHP page?

The PHP gets parsed, it isn’t in the end result that is served to the user, so all of the PHP code is purely for processing and doesn’t make its way to the end user.

Also, you really should look into MVC to help reduce the HTML/PHP inter-mixing. The end result will give you a much cleaner and easier to maintain application. I’d start with a few searches in the PHP category and then work up any additional questions you may have on MVC into a new topic.


This is known as “short tags”
If the ini has them disabled the code will break.
If they are enabled you will have problems if there are any <?xml tags or other <?--- tags

If it your own server and you know short tags are, and will always be, enabled you can get away with it.

But if you are writing code others will use, or if you’re uncertain if short tags will always be enabled IMHO it is best to simply explicitly identify the PHP code with <?php and not <?

AFAIK the few extra characters have never caused a performance problem.

1 Like

I took that to mean @bbparis was replying to @Pepster who had said “it’s only three letters”, to add that when you’re in and out of php many times in a large page, those three letters mount up each time you type them, rather than a performance issue.

IMHO you should not be “in and out of php many times” that is a problem in its own

1 Like

Not sure it’s quite aimed at a beginner to PHP but:

I’ve found that a good tutorial series about MVC

Other notes on short tags.

As of PHP 5.4 the short echo tag, <?= , has been available regardless of the setting of php short tags. That was the compromised reached regarding their use.

The short tag plays hell with validators and IDE’s, but not so much for browsers since it’s already been parsed.

Code portability issues are overstated in my opinion. The vast majority require mod_rewrite to be setup somehow, usually through an .htaccess file. It is flat out impossible to stop your .htaccess file from turning on short tags using the appropriate php_flag. This said, I’ve never used the short tag myself, though I do use the short echo tag.

First of all, I appreciate your help and feedbacks, they are important for me. Thank you all.

I think also it is a good way to learn :wink:

for that I’m going to use <?php balba... ?>

This is the first time that I know that there is a technologie called IMHO, and I got a better idea by reading the following : https://dayone.me/1sfzMa, unless this word means something else…

This is exactly what I was talking about, but anyway, I understand that is better to user <?php to avoid many problems, voilà !

Interesting, I keep this video ( or videos as I discovered on yourtube ) to watch them later.


You could always use PHP long tags if you really like typing (I’ve never seen anyone actually use this but it does work)

<script language="php">balba ... </script>

Looks like that may have changed in PHP 5.5. I’ve got short tags disabled and tried the following test script:


echo 'Does This Work?';

PHP’s parser doesn’t like it:

( ! ) Parse error: syntax error, unexpected ‘echo’ (T_ECHO) in C:\wamp\www\sandbox\tag_test.php on line 3

There’s no .htaccess file at all in the folder where the script was run from

Try deleting the “echo”.

<?= 'Does This Work?' ?>

Of course it doesn’t

<?= is the short tag equivalent of <?php echo giving you

<?php echo

echo 'Does This Work?';
1 Like

I am getting the same error as you Space Phoenix viz.
Parse error: syntax error, unexpected ‘echo’ (T_ECHO) in /home/petalsan/public_html/testingfooter.php on line 1
in a new page I am coding having PHP set up as
<?php // code here ?>

How do I get the code to run? It is on a remote site.

The silly thing is that I have PHP is some other pages as
<?php include 'navigation.php'; ?>
and they work fine.