PHP : Convert/Replace Short Open Tags

Using short open tags, such as <? on your PHP code is not so clever. Other than the debate going on whether short open tags won’t be available on PHP6 or not, it is possible that your shared hosting has disabled it for some reason, or you might have to migrate your code sometime somewhere it is not supported any longer. For the sake of clean coding, always use clean tags. Other than obeying the standards for technical reasons, it is also essential for developing clean, easy-to-read codes for yourself, other people reading your code or even the IDE/Framework you’re using!

If somehow, this article is the first place you’ve realized you should stop using short open tags, it’s never too late! Below is a find / sed line to convert your php files from short open tags to “normal” ones. This line works pretty good but it’s always a good idea to backup your scripts before doing such massive automated injection.


find . -iname '*.php' -type f -print0 |xargs -0 sed -i -e 's/<? /

Don’t forget that this line will look for *.php files under the current folder due to the dot (.) which is the first argument of the find command.
It will apply these replaces:

From To
<? <?php
<?// <?php //
<?/* <?php /*
<?= <?php echo
  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Compile and build Apache + MySQL + PHP from the source [cite]

This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP...

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Installing MS SQL Module to PHP on DirectAdmin [cite]

If you need to connect to an MS Sql Server remotely from your DirectAdmin server via php, you...

Firewall Settings With IpTables on CentOS and RedHat [cite]

Here on this article we’ll discuss some basic methods to quickly apply to the iptables...

How to change storage engine to InnoDB in MySQL?

You’ve designed a database with MyISAM and suddenly realized that you need ACID (atomicity,...