<?php
/*

Wordpress leading whitespace fix

================================ Ever had poorly coded plugin/theme output whitespaces causing your RSS to stop working? You can fix that using this simple script. Download -------- Plaintext version: http://wejn.org/stuff/wejnswpwhitespacefix.php VIM Syntax colored: http://wejn.org/stuff/wejnswpwhitespacefix.php.html Requirements ------------ Works with PHP5 only, as the headers_list() function is missing in PHP4 which makes output Content-Type detection impossible. Installation ------------ Either use this as auto_prepend in your .htaccess: php_value "auto_prepend_file" /path/to/wejnswpwhitespacefix.php or include it as first thing in Wordpress' index.php file even before that "short and sweet" line: <?php include("wejnswpwhitespacefix.php"); // Short and sweet define('WP_USE_THEMES', true); require('./wp-blog-header.php'); ?> Author: Wejn {wejn at box dot cz} License: GPL v2.0, no latter version(s) */ function ___wejns_wp_whitespace_fix($input) { /* valid content-type? */ $allowed = false; /* we mangle the output if (and only if) output type is text/* */ foreach (headers_list() as $header) { if (preg_match("/^content-type:\\s+text\\//i", $header)) { $allowed = true; } } /* do the actual work */ if ($allowed) { return preg_replace("/\\A\s*/m", "", $input); } else { return $input; } } /* start output buffering using my custom callback */ ob_start("___wejns_wp_whitespace_fix"); ?>