I need to store some data in a text file. The data is in my mysql as latin1 to use as few bytes as possible. How can I make a text file for php to write to in latin1 format please?
-
Using UTF-8 won't take up any more space unless it actually needs to. Is the usage of latin1 set in stone? (Bit retrograde, hence the question.)John Parker– John Parker2011-01-20 22:29:05 +00:00Commented Jan 20, 2011 at 22:29
-
Not set in stone as such, just storing a LOT of text (a-z and 0-9) no fancy stuff, so thought their might be a wayDavid19801– David198012011-01-20 22:33:02 +00:00Commented Jan 20, 2011 at 22:33
1 Answer
Whilst slightly off-topic, to be honest I'd be tempted to keep everything (web page, database connection, table/collation, output files, etc. in UTF-8), purely in the (quite possibly epically unlikely) eventuality that non latin1 characters are required at any point in the future.
Virtually all text editors, etc. support UTF-8 as-is and it'll be easier to convert from UTF-8 to another format (and conversely from another format to UTF-8) if so required. Additionally, database (and disk space) is ridiculously cheap, so using up a few bytes here and there in comparison to committing to a limited character set would seem a bit of an excessive trade-off.
Incidentally, there's a fairly canonical blog post related to such things by Joel Spolsky called: "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)". It's well worth a read irrespective of which way you decide to go.