PHP Whitespace check

Did you ever find yourself with unwanted whitespace at the start or end of your document? A tip to prevent this beforehand is to never close the PHP file with a _?> _tag. These tags are not required. It is a common practice on several projects.

If this is too late and you do have whitespace, execute the snippet below in the root folder to find the culprit.

<?php
foreach (glob('\*\*/\*.php') as $file){
	if (preg_match('/\?'.'>\s\s+\Z/m',file_get_contents($file)))
		echo $file . PHP_EOL;		if( preg_match('/^[\s\t]+<?php/', file_get_contents($file)) )
		echo $file . PHP_EOL;
}

This code will match both the whitespace starting before the open and after the close tag.