Php Return Contents of an Include as String
Posted:
Tuesday, May 5th, 2015Last modified:
Tuesday, May 5th, 2015Topics:
PHPOverview
Sometimes you may want to get the contents of a file after it has been parsed by the PHP interpreter. This function uses output buffering to capture the contents of an included file and returns the result as a string. The function definition is taken verbatim from the PHP include manual page.
/** * Returns the contents of an include as a string. */ function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; return ob_get_clean(); } return false; }
References
PHP: include - Manual | http://www.php.net/manual/en/function.include.php
Available Wiki Topics
The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.