Plummet Posted September 20, 2010 Share Posted September 20, 2010 (edited) Hello.I figured one critical problem for my code. My task is to modify the contents of a UTF8-encoded file (replace certain substrings in the right lines). I can't open it with FileOpen($file, 2), since it will rewrite the file in ANSI. So I open it with$hFile = FileOpen($sFile, 256)UTF8, no BOM. Then I try to use FileWrite:FileWrite($hFile, $someMysteriousText)Then I close the file with FileClose, and ... the file contents remain unchanged. It'll be cahnged if I use the modes 1 or 2 though (write with append/write with erase). How can I correctly write to UTF8 files?By the way, there's another problem with those modifiers — it is impossible to erase-write into file, only to append-write. But this is solvable by a hack (opening in ANSI for erase-write, writing "", closing, opening for UTF8 write). If only UTF-write will work. Edited September 20, 2010 by Plummet Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 20, 2010 Share Posted September 20, 2010 As the helpfile says,0 = Read mode (default)So to write "UTF8 (without BOM)" use 256+1 (or 257). If you use 2 instead of 1 all content will disappear. This is all in the helpfile if you look at FileOpen().it is impossible to erase-write into file, only to append-writeDon't understand what you mean there. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Plummet Posted September 20, 2010 Author Share Posted September 20, 2010 Hm, helpfile says „Can be a combination of the following:“, where 0 is for read, 1 is for write and append, 2 is for write and erase, 256 is to „Use Unicode UTF8 (without BOM) reading and writing mode“. I wasn't clearly understanding what the „combination” is in this context, but if it's simply a sum... thanks a lot! I'll go trying it. Link to comment Share on other sites More sharing options...
Plummet Posted September 20, 2010 Author Share Posted September 20, 2010 Yeah, it's working. May be it'll be useful to define what is the combination explicitly in the docs Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now