Difference between constant DATE_W3C on different PHP versions

Submitted by Jochus on Tue, 12/10/2010 - 00:40 | Posted in:

I came across this "bug" in PHP when I was using the http://drupal.org/project/xmlsitemap module of Drupal on different servers (different PHP versions).

What is XMLSitemap?
The XML sitemap module creates a sitemap that conforms to the sitemaps.org specification. This helps search engines to more intelligently crawl a website and keep their results up to date. The sitemap created by the module can be automatically submitted to Ask, Google, Bing (formerly Windows Live Search), and Yahoo! search engines. The module also comes with several submodules that can add sitemap links for content, menu items, taxonomy terms, and user profiles.

So on the first server, Google was perfectly processing the sitemap.xml file. But on the second server, Google was telling me the format of the sitemap.xml was invalid (including linenumber, luckily :p ...). That was awkward, as I was using the same version of XMLSitemap (version 1.2).

After looking in the XML file, I noticed some differences:
First server:

<lastmod>2010-10-11T15:52:01+00:00</lastmod>

Second server:

<lastmod>2010-10-11T15:52:01+0000</lastmod>

As you can see, there's a colon missing in the second version.
The code which is producing these lines is in xmlsitemap.pages.inc

...
      $link->output .= "\t<lastmod>". gmdate(DATE_W3C, $link->changed) ."</lastmod>\n";
...

The problem is related to the DATE_W3C constant. In PHP 5.1.2, the constant is different to PHP 5.2.14. More information? http://bugs.php.net/36599

I fixed this bug by changing the line into:

...
      $link->output .= "\t<lastmod>". gmdate('Y-m-d\TH:i:s+00:00', $link->changed) ."</lastmod>\n";

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.