Thursday, January 24, 2008

variable variables in php

i was doing a small function for a php driven web site.

client wanted to put meta data in a simple flat file and site it self should be able to grab and insert in between the head tags, on the fly. yeah it's not a big deal :)

but, with php variable variables, it's pretty interesting!


function getMetaData($metaVarName, $type) {
require './meta_data.php';

return ${strtoupper($type)}[$metaVarName];
}


meta_data.php looks some thing similar to this.


$TITLE['home'] = "This is home page";
$TITLE['about'] = "This is about page";
$TITLE['map'] = "This is map page page";
$DESC['home'] = "This is home page blah blah";
$DESC['about'] = "This is about page blah blah";
$DESC['map'] = "This is map page blah blah";
$KWRD['home'] = "home page key words";
$KWRD['about'] = "about us key words";
$KWRD['map'] = "map key words";

0 comments: