this one-liner may work for you:
awk '/<?php/{f=1} /?>/&&f{print;f=0} f' file
if you don't want the <?php
and ?>
in output:
awk '/<?php/{f=1;next;} /?>/&&f{f=0} f' file
test: (I hope the output is what you are looking for. to save to new file, you could redirect output to a new file)
kent$ cat test.txt
<?php
all
text
here
should
be
saved
even if
empty
lines
?>
foo
bar
should be removed
kent$ awk '/<?php/{f=1} /?>/&&f{print;f=0} f' test.txt
<?php
all
text
here
should
be
saved
even if
empty
lines
?>