Hi,
I've got some files that are UTF-8 encoded, but without the byte-order-marker. I know there must be a way to add the needed characters to the beginning of these files, but I'm not sure how to do it.
Any ideas?
Thanks!
andy
How to add a UTF-8 Byte-order-marker to a file?
-
avsfan
- Posts: 554
- Joined: 29 Jun 2006 09:00
- Location: Fort Collins, Colorado
-
bdeshi
- Posts: 4256
- Joined: 12 Mar 2014 17:27
- Location: Asteroid B-612
- Contact:
Re: How to add a UTF-8 Byte-order-marker to a file?
So, did I just discover that there's no easy way for reading/writing raw bytes in XY?
this a workaround:WARNING: this doesn't check if the input file is UTF8-encoded, already has BOM, or even if it is a textfile at all. This just blindly adds the BOM characters to the beginning of the input file.
this a workaround:
Code: Select all
"add bom to file"
$file = "UTF8_file_without_BOM.txt";
writefile($file, hexdump('EFBBBF',2,'ri').readfile($file,'b'), , 'b');Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
avsfan
- Posts: 554
- Joined: 29 Jun 2006 09:00
- Location: Fort Collins, Colorado
Re: How to add a UTF-8 Byte-order-marker to a file?
Thanks, Sammay! Works great!
XYplorer Beta Club