Using sed to convert PHP short open tags to proper tags

In the good ol’ days of PHP is was quite accepted to just use <? to signify the start of PHP code. PHP installs by default would accept this short notation so you could safely distribute scripts that made use of it. However, in the days of XML, this short notation is a little more dangerous, so PHP now comes with short_open_tags turned Off.

This is a short little command line snippet that uses sed to convert all of the php files in a specified directory from the old short tags, to the proper and full <?php tags:

for file in *.php
do
sed -i 's/<?$/<?php/' $file
sed -i 's/<? /<?php /' $file
done

Enjoy!

comments powered by Disqus