I ran the RSS xml file through W3C's RSS validator. The results say:

line 2, column 0: XML parsing error: <unknown>:2:0: XML or text declaration not at start of entity

I'm not sure how to approach this one. I searched on drupal.org and found these:

Based on the 2nd link, I tried placing an echo in the current template.php being used and the output appeared after the space right before the XML tag. That means the extra line in the RSS XML was placed there before the theming was invoked, right? Where should I look?

5 Answers 5


Someone left a space at the beginning of a module.


You can either try to find that bit of code with some tool or command OR put this in includes/bootstrap.inc at line 1112:

echo $filename;

The line number could change subject to updates to Drupal 7 so make sure it is inside the drupal_load function:

if ($filename) {
    echo $filename;  //this is your included line
    include_once DRUPAL_ROOT . '/' . $filename;
    $files[$type][$name] = TRUE;

The result will be a long list of the modules being loaded in source code of the page. The space will be right after the module with the problem.


It seems all of the core and contrib modules were solid. It was the premium theme I used. The new line may not have been in template.php but it was in another file invoked from inside template.php.

My approach: In a local development environment, I added an echo statement in suspected areas. When I added echo at the bottom of the template.php, the output appeared as described in the question but when I placed the echo at the start of the template.php, the echo output appeared before the newline so I tracked down inside template.php what functions or other php files it was calling and soon, I found the dependency php file that had extra lines and fixed it.

This might differ in your case though.


As JAmatulli said its mostly because someone left a space at very beginning in template or module or inc file

Here is another way of using grep to find the culprit. Mostly it is module file so...

grep -R -H '^  <?php' modules/**/*.module

This will check all module files withing your module folder ( i am a step back in my sites/all folder in my linux terminal to find culprit.) If you find two spaces leave two space between ^ and

If you just get the filename you can find its path via

locate -br 'culprit.module'

After correcting clear cache. :)

Improvising: grep -R -H '^ *<?php' modules/**/*.module Check for one or more spaces.

For windows: findstr "^ *<?php" *.module Current position inside modules directory, will check for all .module file withing modules and its sub directory.

  • This worked for me: grep -R -H --include=*.module '^ <?php'
    – cdonner
    Commented Jun 24, 2020 at 13:26

Echo gives a long list of module names and finding a space is difficult. Instead I check for the space in the file name only.

if ($filename) {
  if (strrpos($filename, " ")) {
      echo $filename;
  include_once DRUPAL_ROOT . '/' . $filename;
  $files[$type][$name] = TRUE;

In my case I had a leading space in my settings.php file. So the file was included before the first call of drupal_load() in bootstrap.inc.

Showing all included files before the first include called by drupal_load() gave me good insights of where to look at. I placed this code at the same place as in the answers above.

      echo '<pre>'.print_r(get_included_files(), true).'</pre>';
      $GLOBALS['show_once'] = 5;

To check every included file for a space or new line character near to php-tags:

$file_arr = get_included_files();

foreach ($file_arr as $file){

    if(preg_match('/(\s<\?php)|(\?>\s)/mi', file_get_contents($file)) > 0)
          echo 'The file '.$file.' contains spaces or new lines near the php-tags.<br>';


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.