On Mon, Jun 09, 2003 at 12:26:24PM -0500, Wendell Brown wrote:
> >
> >OK, another way....the HTML could be read into a page (fopen())
> >containing the header/footer stuff. You'd have to deal with
> >identification of which page you want loaded, but shouldn't be too hard.
> 
> Here is what I ended up doing....
> 
> http://marc.theaimsgroup.com/?l=php-general&m=105484835424858&w=2

That works.  I did something similar, not to add headers and footers,
but to implement a simple templating system -- the HTML pages had text
like __FIRSTNAME__ and __LASTNAME__ which had to be replaced with
session variables.  The site owner had some very strange ideas about how
they wanted to design their site, and wanted to do the whole thing in
FrontPage, yet customize pages using data from a PHP-based login.

The basic idea is that the customer uploads pages (a few hundred of 'em)
all under their DocumentRoot.  I've got stuff like:

  $base="http://www.example.com";; // URL *without* trailing backslash
  $qu="'" . '"';
  $href="(<a href=[$qu ]*)($base)?/?([^$qu ]+\.html?)";
  $repl="\\1/show.php?what=\\3";

  if (!file_exists($f)) {
    header("Location: $base/show.php?err=missing%20file:%20$f");
  } else
  if ($fd=file_get_contents($f)) {
    $fd = str_replace("__FIRSTNAME__", $_SESSION['fname'], $fd);
    $fd = str_replace("__LISTNAME__",  $_SESSION['lname'], $fd);
    print $fd;
  }

You could of course hide the URLs behind mod_rewrite with something like

  RewriteEngine On
  RewriteRule ^/.+\.php - [L]
  RewriteRule ^/(.+\.html) /show.php\?f=$1 [L]

You could also make the arrays of the str_replace search and replace
fields, if you had multiple things to change.

But back to your issue -- Instead of __FIRSTNAME__ and __LASTNAME__,
just manipulate <body> and </body>, as you did with output buffering.

I'm not sure if either solution has a performance edge over the other.
In both cases, each of the HTML and PHP file get loaded once per page
view, and whether the translation happens in PHP's output buffering or
via mod_rewrite is probably insignificant.

As always, multiple solutions to every problem.  :)

-- 
  Paul Chvostek                                             <[EMAIL PROTECTED]>
  Operations / Abuse / Whatever
  it.canada, hosting and development                   http://www.it.ca/


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

Reply via email to