Skip to content

Instantly share code, notes, and snippets.

@CraigChilds94
Created January 13, 2015 13:42
Show Gist options
  • Save CraigChilds94/1a1449a383b50bcd8a3c to your computer and use it in GitHub Desktop.
Save CraigChilds94/1a1449a383b50bcd8a3c to your computer and use it in GitHub Desktop.
Handy function to parse a php file and store the result without outputting it.
<?php
/**
* Include a php file, and return the
* parsed content. Allows you to use php
* files instead of custom templating
* engines such as blade.
*
* Takes an array of data to pass to the included
* file and calls extract() on it.
*
* @param String $file The file to include (path included)
* @param Array $data Key/value pairs of data which will be extracted
*/
function retrieve($file, Array $data)
{
ob_start();
extract($data);
include($file);
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment