Skip to content

Instantly share code, notes, and snippets.

@tadeubdev
Forked from james2doyle/render-php-file.php
Last active August 3, 2016 22:50
Show Gist options
  • Save tadeubdev/eedadf3e7260d39b3204 to your computer and use it in GitHub Desktop.
Save tadeubdev/eedadf3e7260d39b3204 to your computer and use it in GitHub Desktop.
<?php
function renderPhpFile($filename, $vars = null)
{
if (is_array($vars) && !empty($vars))
{
extract($vars);
}
ob_start();
include $filename;
return ob_get_clean();
}
// usage
echo renderPhpFile('views/templates/index.php', $data_for_view);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment