Home Geschichten Kunst Computer Tindertraum

[current]

simple templating in PHP
(Wednesday 19th December 2001)

Ok. This NOT rocket-science. It is NOT very cool or effective. It simply works and is nice and short code. Templating done the quick way. I just though I'd share this cade with the world, as it is so easy to do ;)
function parsetemplate ($templatestr, $infohash) {
	// replace placeholders like {foo}
	// in templatestr with 
	// corresponding values from infohash
	function lookup ($s, $h) {
		if ($h{$s}) {
			return $h{$s};
		} else {
			return "<!-- unknown: $s -->";
		}
	}
	$result = preg_replace (
		"/{(w+)}/e",
		"lookup('$1', $infohash)",
		$templatestr
		);
	return $result;
}

[ by Martin>] [permalink] [similar entries]

similar entries (vs):

similar entries (cg):

relevant words



Martin Spernau
© 1994-2003

traumwind icon Big things to come (TM) 30th Dez 2002

What are you really thinking about just now?
Oblique Strategies, Ed.3 Brian Eno and Peter Schmidt



amazon.de Wunschliste





 

usefull links:
Google Graph browser
Traumwind 6-Colormatch
UAV News

powered by SBELT