If you’re using PHP to output XML, and you have empty lines outside of your <?php and ?> tags, you may insert empty lines before your opening XML tag - a big no-no. Apparently, that invalidates XML.
To detect this, use this Bash code in a directory of PHP files:
for file in `find -type f -name "*.php"`; do lines=$((`wc -l ${file} | cut -d' ' -f1`+1)); pos=`grep -Hn '?>' ${file} | cut -d: -f2`; `(($lines != $pos ))` && echo $file ; done
Disclaimer: I wrote this code while in an unnatural state (who ever is?). It may break your code, impregnate your cat, cause your baby sister to fall madly in love with your microwave, or really, anything else. It even might (definitely) fail to check for newlines before you opening <?php tag! And it’ll complain if you don’t have a closing ?> tag (you’d be surprised how … inconsistent people may be). Anyway, don’t complain to me.
