Extra bytes being rendered in start of view

Hi,

I am porting an application over from Cakephp 1.2 to 4.3

I have an action which outputs a binary (BIFF format) XLS file via its view.

But I have found that the generated output contains 3 leading bytes 0A 0D 0A before the BIFF header
I have tried removing everything from both the layout and the view template, and I still end up with the 3 bytes 0A 0D 0A (and of course nothing else).

If I try putting something like <?= "Blah" ?> as the only content of the layout, I get 0A 0D 0A the Blah then the BIFF header.

So wherever these 3 bytes are coming from, they are being emitted before the layout is rendered.

Does anyone have any suggestions to where these may be coming from?

Thanks in advance

0D 0A is a CRLF

You should check if any of your PHP files starts with one.
If its present in all of your routes then its probably in something that is loaded all the time like

  • webroot/index.php
  • Anything in your config folder
  • src/Application.php
1 Like

Its also possible you’ve put the closing PHP tag ?> at the end of a file and there is a carriage return (0A 0D is Linefeed & Carriage return) after it. That will get sent as data to the webpage, as text after the closing tag is considered legitimate HTML data - so don’t use the closing PHP tag at the end of files.

Also, its odd the actual data is 0A 0D 0A. If the file is a Windows text file it has 0D 0A at the end of every line, always in pairs. Linux files have just 0A.

Therefore 0A 0D 0A is a mix - it should either be 0A 0D 0A 0D (Windows pairs of characters) or 0A 0A (Linux) - not having a stray 0A. Understandably you want neither, but this could show a bigger issue, that maybe you’ve edited a Linux text file in say Windows Notepad.

So its possible there’s a couple of things going on here to check for.

1 Like

Hi,

Yep, I did realise that they were CR/LF and yep the LF on it’s own could be there as this is on a linux platform, but I didn’t want to make any assumption about it.

What I didn’t fully comprehend was that the trailing ?> tag wasn’t necessary and it turned out to be two model tables that had extra line terminators after the ?>

So I have also gone through all my php files and removed the closing php tag to avoid this happening to me again.

Thanks so much for your replies with your suggestions. It has allowed me to get this dealt to quickly.