Created
January 13, 2015 13:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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