DReade83
asked on
Using PHP replace to text in a page before as it loads
I have the following files:
index.php
page.php
index.php reads the following:
<?
include('page.php'); exit();
?>
page.php contains the following text:
<html><body>
<a href="/index.php?page1">Li nk</a>
</body></html>
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.
index.php
page.php
index.php reads the following:
<?
include('page.php'); exit();
?>
page.php contains the following text:
<html><body>
<a href="/index.php?page1">Li
</body></html>
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER