Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 881623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:33+00:00 2026-05-15T12:17:33+00:00

I am writing a function to dynamically generate my sitemap and sitemap index. According

  • 0

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

According to the docs on sitemap.org, the file should be encoded in UTF-8.

My function for writing the file is a rather simplistic one, something along the lines of:

function generateFile()
{
  $xml = create_xml();
  $fp = @fopen('sitemap', 'w');
  fwrite($fp, $xml);
  fclose($fp);
}

[Edit – added after comments ]

The create_xml() is simplistic, like so:

function create_xml()
{
return '<?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>http://example.com/</loc>
        <lastmod>2006-11-18</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.8</priority>
    </url>
</urlset>';
}

Is there anything in particular I need to do to ensure that the file is encoded in UTF-8?

Additionally, I would like to gzip the file, rather than leaving it uncompressed. I know how to compress the file AFTER I have saved it to disk. I want to know if (how?), can I compress the file BEFORE writing to disk?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:17:34+00:00Added an answer on May 15, 2026 at 12:17 pm

    Yes, you need to make sure your content (the output of create_xml() is encoded as UTF-8. To ensure this, you can use utf8_encode(). You need to make sure the XML file specifies <?xml version="1.0" encoding="UTF-8"?>. And I’d suggest to fopen in the 'wb' mode, the b meaning binary. This will ensure the data gets written exactly as-is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a function that tests for brokens links in an org-mode buffer:
Whats this syntax useful for : function(String... args) Is this same as writing function(String[]
I'm writing a function that fishes out the src from the first image tag
I'm writing a function for an installer DLL to verify the Authenticode signature of
Let's say that I'm writing a function to convert between temperature scales. I want
Say for instance I was writing a function that was designed to accept multiple
I am having some difficulty writing a function that will search through a directory
I find that I frequently end up writing a function that I always call
I'm writing an interactive function that I'd like to have remember the last argument
I am writing a searching function, and have thought up of this query using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.