PHP metadata error in XML open tag

I have a file that includes a file called sitemap.html and in the Sitemap file, 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("Ymd", $content->publish_date); ?></lastmod> <changefreq>monthly</changefreq> <priority><?php echo $content->sitemap_index; ?></priority> </url> <?php endforeach; ?> </urlset> 

Everything looks fine, but I get 500 error message:

PHP password analysis error: syntax error, unexpected "version" (T_STRING) in sitemap.html on line 1

As you can see, I use <?xml and not <?php , so why is he trying to parse it like PHP?

At first I thought it was magic quotes that were causing the problem, but when I do var_dump get_magic_quotes_gpc () , I get bool(false) , so the magic quotes are not even included.

Also, in my php.ini I see that magic_quotes is OFF .

As an alternative to fix it, I replaced the first line with the following text:

 <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> 

But I'm still wondering what is going on.

I have other websites hosted on the same server (PHP version 5.4.45), and I am not getting the PHP Parse Error on the site map of other websites ...

Any idea what might cause this error?

+6
source share
3 answers

You should check the short_open_tag option. As I see, PHP sees <? part of your <?xml as an open php tag and generates an error.

+6
source

If you intend to process PHP HTML pages and work on all other sites, then you (obviously) are dealing with a problem related to a troubleshooting problem.

You can continue to search for short_open_tags settings that are entered somewhere on the server, or you can simply repeat the XML declaration using PHP.

 <?php echo '<?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("Ymd", $content->publish_date); ?></lastmod> <changefreq>monthly</changefreq> <priority><?php echo $content->sitemap_index; ?></priority> </url> <?php endforeach; ?> </urlset> 

Here is the old page on the topic: PHP opening tags and XML declaration

I prefer all PHP code files to expand the .php extension, so it’s clear that they contain code and do not require the overhead of having PHP process each HTML file, but this is just my opinion.

+2
source

As already mentioned, this is due to the short_open_tag option

Tells PHP whether the short form ( <? ?> ) Of an open PHP tag is allowed. If you want to use PHP in conjunction with XML, you can disable this option to use <?xml ?> Inline . Otherwise, you can print it using PHP, for example: <?php echo '<?xml version="1.0"?>'; ?> <?php echo '<?xml version="1.0"?>'; ?> . Also, if disabled, you should use the long form of the open PHP tag ( <?php ?> ).

+1
source

All Articles