I have a function (a preg_replace) to modify a PHP or HTML page with a few things. Right now, the only way I can do this flawlessly is with a wrapper page:

I have a page, called disp.php, that takes a file variable. When you type in disp.php?file=index.php, it loads the file with file_get_contents and uses preg_replace to replace the SQL queries (which is what I'm trying to do) and all of the relative links (i.e. /dir/page.php -> disp.php?file="/dir/page.php").

I thought that there might be an easier way to do this using the prepend and append directives in php.ini. Here's what I can do:

<!-- top.inc -->
<?
$contents = <<<EOD
?>

<!-- bottom.inc -->
<?
EOD;
echo eval(preg_replace("Hello","Goodbye",$contents));
?>

<!-- wraptest.php -->
<?
include("top.inc");
?>
<html>
<body>
Hello!
<? $string="you";
echo "<br>How are $string today?";
?>
</body>
</html>
<?
include("bottom.inc");
?>

The script seems to work perfectly (it displays "Goodbye!", and on the next line, "How are you today?"), except it says there's a parse error on the last line of front.inc! Since the script works otherwise, is there any way to suppress the error? Will this method work with top.inc and bottom.inc in the auto_prepend_file and auto_append_file directives instead of at the top and bottom of the page? I won't have access to a php.ini file for a week, so I can't truly test it, but the documentation said that those directives work like include statements.

Thanks for the help!

-Enu

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to