Its always good practice - not echo data until your application is completely complete, for example
<?php echo 'Start'; session_start(); ?>
now session_start along with another line of functions will not work, since there was already data output as an answer, but by doing the following:
<?php $output = 'Start'; session_start(); echo $output; ?>
This will work and be less error prone, but if necessary to capture the output, you should:
ob_start(); //Whatever you want here $data = ob_get_contents(); //Then we clean out that buffer with: ob_end_clean();
source share