27 July 2007 - 21:24Kickin’ Rad Parkade Ordinance Sign of the Week

This sign is posted in the parkade at the building I work in. It prohibits doing sick stunts on your motorbike while in the parking area.

That or it means “no ghost riding the whip on company property”.

1 Comment | Tags: humor, irl

22 July 2007 - 3:54[How to] create a simple web template using PHP’s output buffer

The PHP output buffer is exactly what it sounds like: it allows us to capture output and, instead of printing it to the screen immediately, set it as a variable and deal with it later on. The “output” could include echoed lines and ordinary markup outside of php tags. For example: if you include a file, you can set all the variables and run all the functions inside it, but save the output and display it in different parts of your template, like the title, meta tags, content etc. In this tutorial, I’ll explain how to use the PHP output buffer to implement very simple template system for your website.

This guide assumes you’ve already got a nice-looking template with something like an empty div for your page content. I’m using /index.php as my template file, and i’ll pass it the same of the page to display as a GET variable.

The template index.php file should look a bit like this:

[/index.php]

<?php//get the page to display, or use home.php if nothing is passed.$page = (!empty($_REQUEST['page'])) ? $_REQUEST['page'] . '.php' : 'home.php' ; //turn on output bufferingob_start(); //get the contents of the file (/pages/home.php etc.).//do this outside of php tags because the file most likely has its own php tags, as well as ordinary html in it.eval('?> ' . file_get_contents($_SERVER['DOCUMENT_ROOT'] .'/pages/'.$page) . '<?php '); //return the contents of the output buffer, and set it as a variable.$page_content = ob_get_contents(); //turn off output buffering, and clear the output buffer so we can do it again just as easily.ob_end_clean(); ?><!DOCTYPE [...]<title><?=$page_title;?></title><meta name="description" content="<?=$meta_description;?>" /><meta name="keywords" content="<?=$meta_keywords;?>" />[...]<div id="page-content"> <?=$page_content;?></div>[...]

The variables $page_title , $meta_description , and $meta_keywords are defined in the page content file ‘/pages/whatever.php’.

A page content file would look like this:

[/pages/home.php]

<?php//define meta and title tags$page_title = 'This is the page title!';$meta_description = 'This is the meta description';$meta_keywords = 'meta keywords, hot dogs, rap music';?><h1>Welcome</h1><p>This is a test of my simple template system.</p><p>I sure hope it works!</p><p><?phpecho 'I can echo things this way too...';?></p>

Then we’d access this page with the uri /index.php?page=home and the script would start the output buffer, then get the contents of home.php and set the variables, but not echo anything until you tell it to. You can do this as many times as you want, if you wanted to include a menu from an external file as well, for example.

2 Comments | Tags: code, how to, web

5 July 2007 - 23:42Mac vs. PC – On gaming

The Parallels people have put out some “Mac vs. PC” spoof ads to promote their virtualization software. I’m not sure I understand the sense in touting the ability to run Windows to sell a Mac.
“Windows is no good, so why not use a Mac….. to run Windows?”
The commercials reminded me of a little comic strip I created last year (yeah, I was doing it before it was cool :p)

Apple’s current ad campaign is irritating, bring back the lovely Ms. Ellen Feiss!

1 Comment | Tags: art, cyberculture, humor, software