Output buffer versus file_get_contents in PHP
What are the differences between these two ways to get the file content? Which one is better and more effective? I think they will both get the same results, but I really don't know which method is better.
For example.
This code uses output buffering to get the contents of the file:
ob_start();
include('foo/bar.tpl');
$output .= ob_get_contents();
ob_end_clean();
This code uses file_get_contents and gets the same results.
$output = file_get_contents('foo/bar.tpl');
+3
Denis
source
to share
1 answer
Well, the second example will just output the contents of the file as raw text , while at the beginning the contents of the file will be parsed with PHP interpreter
, which means that some code PHP
exists inside it, it will be executed!
+4
php-dev
source
to share