Login   Register  
PHP Classes
elePHPant
Icontem

File: OBH.example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jon Gjengset  >  Output Buffering handler  >  OBH.example.php  >  Download  
File: OBH.example.php
Role: Example script
Content type: text/plain
Description: Example on how to use the OBH class
Class: Output Buffering handler
Manage multiple handlers to filter the page output
Author: By
Last change: Better example commenting
Date: 2007-12-28 12:16
Size: 805 bytes
 

Contents

Class file image Download
<?php

require('OBH.class.php');

//First we create the OBH element
$OB = new OBH;

//Next we prepend the output with the string 'Hello'
//Notice regular PHP syntax
// %in% is replaced with the output given, escaped by single-quotes by default
$OB->addH("'Hello'.'%in%'");

//We then run the output through the strtoupper function
$OB->addH("strtoupper('%in%')");

//And then we tell the script to run the output through str_replace BEFORE running the previous output handlers
//As you might also notice, %in% is now escaped for double-quotes (we do this since %in% is in double quotes).
$OB->addHFirst('str_replace("cheese", "world!", "%in%")'ESCAPE_DOUBLE_QUOTES);

//This will send some output to the class
echo ' cheese';

//But the final output will be:
// HELLO WORLD!

?>