How to prevent an included file to generate output in PHP?

include, output, php

Solution

use output buffering, if the included script isnt actually generating content (like doesnt have echos etc) use below

ob_start();
include("myscript.php");
ob_end_clean();

if it does generate needed content, the generated content will be in `$content`.

ob_start();
include("myscript.php");
$content = ob_get_contents();
ob_end_clean();

Problem

I've got a software that generates outputs using a pattern for several records of data. This file is generated in a specific interval, and due the software is closed source I cant change it. My Pattern is something like (Without a trailing CR or LF): ``` <? $elem[]='%putValueOfRecordHere%' ?> ``` The output will be: ``` <? $elem[]='1' ?> <? $elem[]='2' ?> <? $elem[]='3' ?> ``` In fact the software adds a CRLF for each record, including and using this file would add a lot of CRLF to my real used output. I just want to know, whether there is a built in method, to remove these blank lines, when including a PHP file. Otherwise I will have to parse this file, remove all CRLF, save it without CRLF and include the modified file afterwards, which is pretty much effort.

Original source