in reply to Re^2: modify file in place in script? Regex for changing includes from SSI to PHP
in thread modify file in place in script? Regex for changing includes from SSI to PHP
while ( my $html_file = $rule->match ) { rename($html_file, "$html_file.bak") or die; open(my $fh_in, '<', "$html_file.bak") or die; open(my $fh_out, '>', $html_file) or die; while (<$fh_in>) { my @lines = <$fh_in>; for (@lines) { #replace <!--#include virtual="[document path]"--> #with <?php include($_SERVER['DOCUMENT_ROOT'].'[document p +ath]'); ?> if (s/<!--#include virtual="(.*)"-->/<?php include(\$\ +_SERVER['DOCUMENT_ROOT'].'$1');?>/){ my $result = $1; #print the file changed and the document path for the + included file print OUTFILE "$html_file: $result\n"; } print $fh_out $_; } close($fh_in); close($fh_out); }
|
|---|