tags:

views:

235

answers:

1

I've got a MySQL database table with an ISO-8859-1 encoded text field containing user names. When I export that to a text file using PHP I get a normal text file saved on the client computer. When I open it in Word or Excel on a Windows system, it looks good. When I open it on Mac using Word or Excel, the high-ascii characters are wrong.

I know this is due to the Mac using MacRoman and Windows using ISO-8859-1. My question is how can I write a text file that will open up on both platforms and look good on both?

Is there some XML varian that I can wrap around the text that will clue Word into the fact that it's ISO-8859-1 encoded? What magic dust can I sprinkle on a TXT file to clue the os into the fact that it's using another encoding scheme?

A: 

...I get a normal text file saved on the client computer

You actually get a text in a specific encoding. Let's assume it's ISO-8859-1.

I know this is due to the Mac using MacRoman and Windows using ISO-8859-1. My question is how can I write a text file that will open up on both platforms and look good on both?

The software that opens a text document must know the charset encoding. Sometimes, it can guess it using some heuristics, sometimes it will not try to guess (and use its own default), sometimes you can make him ask you what encoding to use. See here.

There is no general method that guarantees that every user will open it in the correct encoding, as long as we are speaking of pure text files. In some other formats (eg HTML) the encoding can be specified as part of the document itself.

leonbloy
I guess I'm looking for some 'non-pure' text file format then. XML, MIME, ect. Some common format that Word/Excel on both platforms will read correctly. Something with information like the charset meta tag in HTML.
Dan Berlyoung
I think that if you convert it to UTF-8 encoding, with BOM, most sofwtare will detect it right.If not, you can always wrap it in a html page with a charset specification and a PRE tag... It depends of your scenario (is it an automated process ? must it be read by 'internal' people ? does presentation matter, etc)
leonbloy