Is there a way to perform search and replace on PHP code before it is interpreted by PHP engine ?
Desired timeline:
- PHP code is
<?php echo("hello"); ?>. - Search and replace operation is
hello→good bye - PHP code is now
<?php echo("good bye"); ?>. - PHP engine interprets the code (output is
good bye).
It is possible to manipulate the output of the PHP engine, using ob_start or even mod_substitute as an output filter of Apache. However, is it possible to manipulate the input of the PHP engine (PHP code, request, etc)?
Edit:
I’m working with thousands of PHP files and I don’t want them to be modified. I would like to replace host1 with host2 in these files, since the files were copied from host1 and they have to be executed on host2. Indeed, several tests are made on the host name.
You could use a php script that opens a
.phpfile, makes the necessary replacement, thenincludes that file.