On my website, I need to enforce a header on all the various subdomains. For those that are not under my immediate control, I use a little trick with the auto_prepend and auto_append ability of php: I use the prepend script to start output buffering and then use the append script to get the value of the title, etc. and everything between the <body...> and </body> tags. I take those values and stick them into my own template. (OK, that may be a bit "big-brother" of me, but it lets them do their own thing but still makes it fit into the whole.)
It worked fine until I we switched servers. (I'm not in charge of the setup) Now it works until the size of the html file to be operated on reaches somewhere around 10,000 characters. At that point, the ereg command fails to match.
Evidently, there is a variable somewhere that controls how much you can put into an ereg; anybody know what that variable is?
Here is the relevant code:
auto_prepend
// define a custom error handler
function eh($type, $msg, $file, $line, $context) {
// snip
}
set_error_handler("eh");
// test for mysql connect
// snip
// if mysql is down, load certain dummy functions, else load phplib
// snip
// capture document output
ob_start();
auto_append
// load document into $file_text
$file_text = ob_get_contents();
ob_end_clean();
// extract title
unset($regs);
preg_match("|<title>(.*)</title>|i",$file_text,$regs);
$document_title = $regs[1];
// extract body of document
unset($regs);
eregi("<body(.*)</BODY>",$file_text,$regs);
//preg_match("|\<body(.*)</body>$|i",$file_text,$regs); // I don't have the foggiest why this doesn't work
// now get everything after the ">" of the body tag.
ereg(">(.*)",$regs[1],$temp);
$document_body = $temp[1];
// insert these variables into the official template...
// snip
The title grab always seems to work, but it doesn't always get the content of the body. I can make it quit working by simply adding more content.
Thanks for any ideas 🙂