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 4250476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:32:01+00:00 2026-05-21T04:32:01+00:00

how can I force PHP to add the BOM when using utf8_encode ? Here’s

  • 0

how can I force PHP to add the BOM when using utf8_encode ?

Here’s what I am trying to do:

$zip->addFromString($filename, utf8_encode($xml));

Unfortunately (for me), the result will not have the BOM mark at the beginning.

  • 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-21T04:32:02+00:00Added an answer on May 21, 2026 at 4:32 am

    Have you tried adding one yourself?

    The UTF-8 BOM seems to be 0xEF 0xBB 0xBF, so you can attach it to your string after conversion to UTF-8.

    $utf8_with_bom = chr(239) . chr(187) . chr(191) . $utf8_string;
    

    Watch out, though. utf8_encode wants an ISO-8859-1 string. If you’re working with XML, make sure that the XML isn’t already UTF-8 encoded. The comments on the documentation suggest that the function is broken in a variety of fun ways, so you shouldn’t throw it around unless you know that you need it.

    Remember, PHP strings are simply dumb, unknowing bytes. They don’t have a character set attached to them, so if the data in the string is already UTF-8, you don’t need to run the conversion.

    Also, the linked Wikipedia article says this:

    While Unicode standard allows BOM in UTF-8, it does not require or recommend it. Byte order has no meaning in UTF-8 so a BOM only serves to identify a text stream or file as UTF-8 or that it was converted from another format that has a BOM.

    You probably don’t need to bother with the BOM tapdance to begin with.

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

Sidebar

Related Questions

Can someone please help me to force my website to redirect to using www.
So I have a webpage that queries some data based on this parameter search.php?state=AL
I created a php website that would simply load the text from a mysql
I found this article: http://www.deluxeblogtips.com/2010/05/editor-style-wordpress-30.html I created a child theme using the Twentyten theme
This isn't much of an issue with MySQL per-se. The Full Story I'm writing
I'm working on a website where I sell products (one class Sale, one class
I have developed a download/upload manager script. When I upload a file via POST
My issue is similar to How to use the Value of a Selected Value
After some work in C and Java I've been more and more annoyed by
I have set up a login system that checks a mysql db validating username,hashed

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.