【问题标题】:Output Buffer versus file_get_contents in PHPPHP 中的输出缓冲区与 file_get_contents
【发布时间】:2014-10-07 20:17:04
【问题描述】:

这两种获取文件内容的方式有什么区别?哪一个更好更高效?我认为他们都获得了相同的结果,但我真的不知道哪种方法更好。

例如。

此代码使用输出缓冲来获取文件的内容:

ob_start();
include('foo/bar.tpl');
$output .= ob_get_contents();
ob_end_clean();

此代码使用 file_get_contents 并获得相同的结果。

$output = file_get_contents('foo/bar.tpl');

【问题讨论】:

    标签: php templates file-get-contents output-buffering


    【解决方案1】:

    好吧,第二个示例将文件内容输出为原始文本,而在第一个示例中,文件内容将由PHP interpreter 解析,这意味着如果其中存在一些PHP 代码它,它会被执行!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多