dsgo31121 2017-03-21 19:33
浏览 14
已采纳

如何在关闭php标签后安全地包含可能有空格的php文件?

I just spent an hour tracking down a bug in a php script that creates an XML file which would not parse because there was a blank line at the end of it (probably just a cut-and-paste bug), I would prefer that my script not be susceptible to these kinds of errors in included file in the future.

Is there any way to ensure that using the include or require_once functions doesn't result in any output? Unless I'm using one as a template, I'm usually using these functions so I can include functions in other PHP files and have no expectation that they have any HTML embedded in them.

  • 写回答

1条回答 默认 最新

  • dongzhangnong2063 2017-03-21 19:44
    关注

    You could start output buffering capture, then include the file then discard any outputted content:

    ob_start(); 
    include 'file.php'; 
    ob_end_clean();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加