Converting PHP scripts that still use « short-tags »

This is a translation of an older article (original in French).

If you kept bad habits or you just got some old PHP scripts that were still using PHP short tags (i.e. (<? ?> instead of <?php ?>) which are disabled by default in current PHP versions, the following script ( is for you:

find "$@" -name "*.php" -exec perl -i -wpe 's/<?=/<?php echo /g' {} ; 
-exec perl -i -wpe 's/<?(?!php|xml)/<?php /g' {} ;

After downloading this script, make it executable:

chmod +x

Then you can use it like this (don’t forget to make a backup of your precious scripts, you never know…):

./ /path/to/your/php/files/

Note that you can specify more than one path from this command line.

5 réflexions sur « Converting PHP scripts that still use « short-tags » »

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *