Multipage formatting of static content using php's output buffer and DomDocument
Problem: Country profile pages on FamilyEducation's reference site http://www.infoplease.com needed to be reformatted using multiple pages and an index for each of the countries. The data for these pages is currently in flat files containing all of the html to generate these pages. There are some rudimentary templates using php to dynamically generate pages on infoplease.
Here is an example of the reformatted country profile page - I apologize in advance for the bombardment of roadblocks and pop-up ads:
http://www.infoplease.com/ipa/A0107264.html
In order to do this I had to intercept the output of the country page using PHP 5.x ob_start and ob_flush.
I would start ob_start in the banner template of the page, if the page was a country profile page, this was determined by a meta-tag stating this.
BANNER:
<?php
if ($IP_DEV && ($IP_CHUNK == "COUNTRY-SEC" || $IP_CHUNK == "TERRITORY-SEC")) {
include "$IP_LIB_DIR/PageSplitter.php";
ob_start(create_function('$text','return PageSplitter::pageSplitCallback($text);'));
I then used a lambda function in the ob_start command which called back the php class "PageSplitter.php - this is class is attached to the bottom of this page.
The footer template would then flush the completed page to browser output.
FOOTER:
<?php
if ($IP_DEV && ($IP_CHUNK == "COUNTRY-SEC" || $IP_CHUNK == "TERRITORY-SEC")) {
ob_end_flush(); // used to flush country page output started in banner.php
| Attachment | Size |
|---|---|
| PageSplitter_php. | 6.07 KB |

