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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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.Watch out, though.
utf8_encodewants 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:
You probably don’t need to bother with the BOM tapdance to begin with.