Wednesday, April 1, 2009

How to parse a PHP file and get contents

file_get_contents function only gets a file contents, but it does not parse it. So if you are interested in parsing a file, and the get its contents, here is the way:

ob_start();
include($filename);
$return_str = ob_get_contents();
ob_end_clean();

So using output buffering, we will include the file, and then get the output result in a variable.

No comments: