I'm writing a function to dynamically generate my sitemap and sitemap index.

Based on the paperwork on sitemap.org, the file ought to be encoded in UTF-8.

My function for writing the file is really a rather simplistic one, something like:

function generateFile()

[Edit - added after comments ]

The create_xml() is simplistic, like so:

function create_xml()

world wide web.sitemaps.org/schemas/sitemap/.9"

    xmlns:xsi="http://world wide web.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://world wide web.sitemaps.org/schemas/sitemap/.9

                http://world wide web.sitemaps.org/schemas/sitemap/.9/sitemap.xsd">








Can there be anything particularly I have to do to make sure that the file is encoded in UTF-8?

Furthermore, I must gzip the file, instead of departing it uncompressed. I understand how to compress the file Once I have saved it to disk. I wish to determine if (how?), can one compress the file BEFORE conntacting disk?

Yes, you have to make certain your articles (the creation of create_xml() is encoded as UTF-8. To make sure this, you should use utf8_scribe(). You have to make certain the XML file identifies <?xml version="1." encoding="UTF-8"?>. And I'd suggest to fopen within the 'wb' mode, the b meaning binary. This can make sure the data will get written just as-is.

Your PHP script files ought to be saved as utf-8.

Also, it's difficult to express more without seeing what create_xml() does

If you work with only ASCII figures, your file is going to be forever in UTF-8.