From 620ee834d03b359fa3e5e02a17eb779e149e4dd7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 7 Feb 2014 11:56:48 +1300 Subject: [PATCH] Docs for whitespace fixes --- docs/en/installation/common-problems.md | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/en/installation/common-problems.md b/docs/en/installation/common-problems.md index f824e232d..2a5270594 100644 --- a/docs/en/installation/common-problems.md +++ b/docs/en/installation/common-problems.md @@ -74,3 +74,38 @@ needs to create/have write-access to: * The mysite folder (to create _config.php) * After the install, the assets directory is the only directory that needs write access. * Image thumbnails will not show in the CMS if permission is not given + +## I have whitespace before my HTML output, triggering quirks mode or preventing cookies from being set + +SilverStripe only uses class declarations in PHP files, and doesn't output any content +directly outside of these declarations. It's easy to accidentally add whitespace +or any other characters before the `` closing braket at the end of the document. + +Since we're dealing with hundreds of included files, identifying these mistakes manually can be tiresome. +The best way to detect whitespace is to look through your version control system for any uncommitted changes. +If that doesn't work out, here's a little script to run checks in all relevant PHP files. +Save it as `check.php` into your webroot, and run it as `php check.php` (or open it in your browser). +After using the script (and fixing errors afterwards), please remember to remove it again. + +```php + $file){ + if($file->getExtension() != 'php') continue; + if(preg_match('/thirdparty|vendor/',$file->getPathname())) continue; + $content = file_get_contents($file->getPathname()); + if(preg_match('/^[[:blank:]]+<\?' . 'php/', $content)) { + echo sprintf("%s: Space before opening bracket\n", $file->getPathname()); + $matched = true; + } + if(preg_match('/^\?' . '>\n?[[:blank:]]+/m', $content)) { + echo sprintf("%s: Space after closing bracket\n", $file->getPathname()); + $matched = true; + } +} +``` \ No newline at end of file