save File XML as UTF 8 with BOM

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

save File XML as UTF 8 with BOM

Post by dimitris »

How can i add a BOM signature (EF BB BF in hex) at the top of my file i save with PHP

My Code:

Code: Select all

$fp = fopen('test.xml', "w+");
fwrite($fp, $fileXML);
fclose($fp);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: save File XML as UTF 8 with BOM

Post by requinix »

Code: Select all

$fp = fopen('test.xml', "wb"); // note the 'b' flag for Windows compatibility
fwrite($fp, /* something goes here */);
fwrite($fp, $fileXML);
fclose($fp);
You aren't reading from the file so don't request it (w+ = read and write, w = only writing).
Post Reply