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

I'm using a simple PHP library to add documents to a SOLR index, via
Can someone please help me to force my website to redirect to using www.
Using this php script, I can call a webservice. The file names will be
I was wondering how i can force a user who has requested a page
How can I force the input's onchange script to run before the RangeValidator's script?
When viewing someone else's webpage containing an applet, how can I force Internet Explorer
I am using PHP with Apache on Linux, with Sendmail. I use the PHP
Anyone knows how i can add a anchor to a web page that will
I'm working on a PHP application, and I'd like to add access control to
I'm trying to build a C++ extension for python using swig. I've followed the

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.