I have a file that is including a file named sitemap.html
and in the sitemap, I have the following code:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc><?php echo SITE_URL . '/'; ?></loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>
<?php foreach ($this->data->content as $content): ?>
<url>
<loc><?php echo SITE_URL . $content->permalink; ?></loc>
<lastmod><?php echo date("Y-m-d", $content->publish_date); ?></lastmod>
<changefreq>monthly</changefreq>
<priority><?php echo $content->sitemap_index; ?></priority>
</url>
<?php endforeach; ?>
</urlset>
Everything seems okay, but I'm getting an error 500 that's saying:
PHP Parse error: syntax error, unexpected 'version' (T_STRING) in sitemap.html on line 1
As you can see, I'm using <?xml
and not <?php
so why is it trying to parse it as PHP?
At first, I thought it was the magic quotes that are causing an issue, but when I do a var_dump of get_magic_quotes_gpc(), I get bool(false)
so the magic quotes aren't even on.
Also, in my php.ini
, I see that magic_quotes
is OFF
.
As an alternative to fix it, I replaced my first line with the following:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
But I'm still curious about what's happening.
I have other websites hosted on the same server (PHP version 5.4.45), and I don't get the PHP Parse Error on the sitemap of the other websites...
Any idea what might be causing this error?
You should check short_open_tag
option. The way i see it, PHP sees <?
part of your <?xml
as a php open tag and generates an error.