I have a unicode string received over HTTP Post or fetched from a DB (does not matter)
In PHP I checked the encoding of the string using "mb_detect_encoding" and got UTF-8 as the result.
SO therefore the string is in Unicode.
But how do I write the string from php to a output file with the proper encoding
$fd = fopen('myfile.php', "wb");
fwrite($fd, $msg."\n");
What I see is "टेसà¥à¤Ÿ" instead of the actual string which is टेस्ट्
Pasting the 'junk' into Notepad++ and then from menu option doing 'encoding UTF-8' will show the proper text.
EDIT *SOLUTION*
Sorry for posting the question and figuring out the answer myself.
I found the solution at the following site http://www.codingforums.com/showthread.php?t=129270
function writeUTF8File($filename,$content) {
$f=fopen($filename,"w");
# Now UTF-8 - Add byte order mark
fwrite($f, pack("CCC",0xef,0xbb,0xbf));
fwrite($f,$content);
fclose($f);
}