Page 1 of 1

save File XML as UTF 8 with BOM

Posted: Fri Dec 12, 2008 6:56 am
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);

Re: save File XML as UTF 8 with BOM

Posted: Fri Dec 12, 2008 1:42 pm
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).