The php closing tag “?>” near end fo file can cause unwanted output to be sent before if followed by some spaces and/or newlines. Here is a regex I made to find?>near eof…

The regex


The breakdown

\?escapes the ? since that is a special char
(?s:.) catch any character including newlines
{0,10} …0 to 10 of those
\Z match end of string ignoring newlines

For the (?s:.) discussion, see

Allow a .php file to end with “?>”

… just change “0″ to “1″:


The Why

For your favorite IDE, to prevent PHP from doing funny stuff (most ofter “Cannot modify header information – headers already sent by somefile on a_line”) .