Hi,
I my code i am using open tag like this <?PHP its working fine but if i use <? that time its showing entire code its not showing html pages

Please can anyone tell me how to fix this problem

Regards
Punitha pary

Dani AI

Generated

— when your page prints the PHP source instead of executing it, the server is simply not recognizing the short tag <?. That behavior is controlled by PHP's configuration: the short_open_tag setting tells the parser whether <? is treated as PHP. For up-to-date details see PHP's tag documentation and the short_open_tag directive.

and are right to recommend <?php for portability. Also note <?= (the short echo) is safe to use on modern PHP versions — it has been always available since PHP 5.4 — but plain <? remains nonportable unless the server is configured to allow it.

A few practical notes that clarify earlier replies: the ini_set(...) trick shown by will not reliably make the parser treat <? as PHP in the same file, because tag recognition happens before the script executes. To actually enable short tags you must change server configuration (for example, set short_open_tag = On in php.ini and restart the web server) or, on Apache with mod_php, enable it per-directory:

# Apache + mod_php
php_flag short_open_tag On

If you cannot change server settings (shared hosting, PHP-FPM, etc.), either keep using <?php/<?= or convert files automatically. A safe bulk-conversion example using Perl (back up files first) converts <? to <?php while leaving <?= and <?xml untouched:

perl -0777 -pe 's/<\?(?!php|=|xml)/<?php/gi' -i.bak *.php

Quick diagnostics: create a small file with <?php phpinfo(); ?> and open it to check the current short_open_tag value. If changing server config is not possible, using full <?php remains the most robust solution.

Recommended Answers

All 6 Replies

it is a setting in the config file. it is recommended to use the long tag.

There are several solutions to this problem. You could modify your php.ini file to allow php short tags. Or if you don't have access to the core php.ini file you can add the following code to the very top of your document.

<?php ini_set('short_open_tag',1); ?><?

You can enable short tags, however, there are other servers (like yours) which do no have the short tags option on.

This means that if you deploy the code onto another server, it may not run.
As pritaeas says, it is recommended to the the full <?php opening tag. There is no real reason not to use them.

I think the main reason why people prefer short tags is that they are faster to type with 60% less letters/symbols to type. Also they look neater but as previously mentioned, it is best to use <?php for compatibility as I think short tags a depreciated in php6.

It's true that short tag has less character to type. But there are many well PHP editor out there, which automatically create a proper <?php ?> syntax with a single click or via hotkey.

It's true that short tag has less character to type. But there are many well PHP editor out there, which automatically create a proper <?php ?> syntax with a single click or via hotkey.

But then how many people RTFM to find out what those hotkeys are? Probably find rarely are hotkeys used even if they are available. Also I think some people might like how it is possible to make the opening tag look a lot like the closing tag which is clean and simple. That is what would make people use short tags a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.