2

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.

2
  • That shouldn't cause newline output. Commented Jul 31, 2013 at 12:09
  • Yes I know, but it does somehow. The solution is already posted below. (The output file has some thousands of lines, maybe there is somwhere something more than a CRLF) Commented Jul 31, 2013 at 12:15

2 Answers 2

11

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();
Sign up to request clarification or add additional context in comments.

1 Comment

really helpful.. i WAS getting 1 as output.. now its giving content.
1

You could use ob_buffers to fetch the output of the file and send the output to oblivion:

<?php
    ob_start();
    include('file');
    ob_end_clean();
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.