I was working on a legacy project recently and it involved moving old php code to a new server. The old code was on a server with php short tags enabled. Short tags allow for the <?php tag that starts a php file or php code block to be written as just <? , a shorter version. The primary issue with PHP’s short tags is that PHP managed to choose a tag (<?) that was used by another syntax, XML.

As this is not standard practice I searched for a way to convert all of the php files in one pass. I  found this linux  command line liner:

find . -name ‘*.phtml’ | xargs perl -pi -e ‘s/(?!(<\?(php|xml|=)))<\?/<\?php/g;’

at Command Line Fu .

Worked like a charm! But be warned. Your mileage may vary.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.