the absolutely fastest way to do it, is to write a program i C and then call that from php with system() or similar.
#include<stdio.h>
int main (int argc, char argv[])
{
FILE fp, *ofp;
char[100] outfile;
char buffer1, buffer2;
strcpy(outfile, argv[1]0;
strcat(outfile, "2");
fp = fopen(argv[1], "r");
ofp = fopen(outfile, "w");
while(!feof(fp))
{
buffer1 = fgetc(fp);
buffer2 = fgetc(fp);
if((buffer1 != '<')&&(buffer2 != '%'))
{
fputc(buffer1, ofp);
fputc(buffer2, ofp);
}
}
fclose(fp);
fclose(ofp);
printf("%s",outfile);
return 1;
}
that is totally off the top of my head and completely untested, but it should work. although this is probably far from the fastest algorithm, the "power of c" will more than make up for it.
you will want to compile it, put it someplace accessible by apache and then call it with popen() so you can harvest the output and get the file name.
please note that there is no file locking on this whatsoever and the whole thing is completely devoid of any meaningful error checking. you'll definitely have to beef it up a bit!
-frymaster