I have a large collection of php files written over the years and I need to properly replace all the short open tags into proper explicit open tags.
change \
My previous answer I just overwrote with sed wont work, sed is too weak for this sort of thing IMO.
So I've whipped up a perl-script that should do the trick, its hopefully very user-editable.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find::Rule;
use Carp;
my @files = File::Find::Rule->file()->name('*.php')->in('/tmp/foo/bar');
for my $file (@files) {
rename $file, $file . '.orig';
open my $output, '>', $file or Carp::croak("Write Error with $file $! $@ ");
open my $input, '<', $file . '.orig'
or Carp::croak("Read error with $file.orig $! $@");
while ( my $line = <$input> ) {
# Replace = with
But note, I haven't tested this on any real code, so It could go "Bang" .
I would recommend you have your code revisioned ( wait, its already revisioned, right? .. right? ) and run your test-suite ( Don't tell me you don't have tests ! ) on the modified code, because you can't be certain its doing the right thing without a fully fledged FSM parser.