Using PHP replace to text in a page before as it loads
Posted on 2007-10-12
I have the following files:
index.php reads the following:
page.php contains the following text:
What I want to do is be able to insert some PHP code which checks-for and replaces any code that matches with "/index.php?" and to replace it with "/newindex.php?", but by placing the code in the index.php file, not into each individual page.
I've tried using preg_replace code to do this, by placing it into the index.php file before the include, but the page loads without any changes being made. Next I tried doing something which I doubted working; placing the code in the same line as the include, as follows:
preg_replace("^\/index.php\?$", "/newindex.php?", "/index.php?" (include('page.php')); exit();
This resulted in a blank page (the server's error correction isn't setup properly yet, so no error message was displayed).
Am I going about this the right way?
There is a proper reason behind this; to add the preg_replace code into the index.php file of a forum package aimed at replacing all references to "index.php" with another filename once the page has loaded, but I want to test it this way first to see if it'll work.
Any help on this would be seriously greatly appreciated. Thanks in advance.