Archive of December 2008


Mon 15 Dec

Perl Find and Replace

I had a web app that I initially wrote with the bad assumption that short tags would always be enabled. Now that I am older and wiser (regarding PHP, anyway), I realized that short tags are an awful thing to force on people. I needed to quickly find and replace all instances of short tags in my application, so I used these two lines of Perl, which I'm posting here so I can easily find them again.

perl -pi -w -e 's/<\?/<\?php/;' *.php perl -pi -w -e 's/<\?phpphp/<\?php/;' *.php

Because I had used the full <?php start tag in some instances, I had to use the second line as well. Thanks to this site for the clear explaination.

· Tags: ,