Return to Snippet

Revision: 3010
at May 23, 2007 10:44 by jgeewax


Initial Code
/**
 * Fetch the files contents -- parsed by PHP -- as if it were included
 *
 * @param string $file
 * @return string
 */
function get_include_contents($file) {
	if (!is_file($file) || !file_exists($file) || !is_readable($file)) return false;
	ob_start();
	include($file);
	$contents = ob_get_contents();
	ob_end_clean();
	return $contents;
}

Initial URL


Initial Description
This was posted on the PHP website, I use it quite often. You may get a warning as it is an "unsafe" include (include($var)), but it's a risk that needs to be taken.

Initial Title
Get Include Contents

Initial Tags
php

Initial Language
PHP