[ 'title' => 'articles' ], 'html' => <<Placeholder for article listings HTML, ]; } $template = file_get_contents('template.inc'); $result = preg_replace_callback('/\[(\w+)\]/', function ($matches) use ($article) { $key = $matches[1]; return isset($article['meta'][$key]) ? $article['meta'][$key] : $matches[0]; // fallback to original if key not found }, $template); $rendered= preg_replace('/\[contents?\]/', $article['html'], $result); debug("PAGE: $page\n" ."TYPE: $type\n" ."FILE: $file\n" ."PATH: {$_SERVER['PATH_INFO']}\n"); echo $rendered;