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 (shorttags.sh) is for you:
#!/bin/sh 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 shorttags.sh
Then you can use it like this (don’t forget to make a backup of your precious scripts, you never know…):
./shorttags.sh /path/to/your/php/files/
Note that you can specify more than one path from this command line.
Are you sure the <?= tag is also disabled? I believe that tag is still valid…
@Frank Groeneveld
I just tried it on my server and <?= doesn’t work here when short tags are disabled.
@jernst
Ok, I’ll have to convert my code than also 🙂
I think this will also convert:
<?xml
to
<?php xml
You could do something like this though:
<?(?!php|xml)
I wrote an article about it here
http://kevin.vanzonneveld.net/techblog/article/prepare_for_php_53/
@Kevin van Zonneveld
You’re right! Thank you for your comment!
I’ve updated the regex accordingly.