White spaces with global.php
#1
First of all, sorry for my english.

I'm developing the next release of my plugin MySEO and when I try to make a sitemap with a single php file in root, with the header() functions and the code correctly, I can see this error:

Quote:This page contains the following errors:

error on line 1 at column 6: XML declaration allowed only at the start of the document

Below is a rendering of the page up to the first error.

The error is showed when I write the code to include global.php file in the file.
This require_once add three whitespaces in top of content.

How can i solve it?

Example of the code:

define("IN_MYBB", 1);
require "./global.php";

global $mybb;
header("Content-Type: application/xml; charset=utf-8"); 

$sitemap = '<?xml version="1.0" encoding="UTF-8"?>'; 
$sitemap .= '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'; 
$sitemap .= '<url>'; 
$sitemap .= '<loc>'.$mybb->settings['bburl'].'</loc>'; 
$sitemap .= '<changefreq>blablabla</changefreq>'; 
$sitemap .= '</url>';
$sitemap .= '</urlset>';

echo $sitemap

Results in:

  <?xml version="1.0" encoding="UTF-8"?>
     <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <url>
               <loc>http://localhost/dev</loc>
               <changefreq>blablabla</changefreq>
          </url>
     </urlset>

With three whitespaces in top of content.

Thanks. Smile
Reply
#2
Try
echo trim($sitemap);

If that doesn't work, try output buffering:
ob_start();
require "./global.php";
ob_end_clean();
Reply
#3
(02-20-2015, 04:35 AM)Destroy666 Wrote: Try
echo trim($sitemap);

If that doesn't work, try output buffering:
ob_start();
require "./global.php";
ob_end_clean();

Thanks, but the problem was in my plugin, one whitespace before ?> tag.

Thanks. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)