Hi all,
I know it sounds counter-productive, but I'm actually trying to convert text from UTF-8 to "MS-ANSI" or "Windows-1252". I'm parsing an RSS feed and spitting out an Excel compatible CSV file (long story). Anyway, I have the following PHP function:
function formatForExcel($fp) {
$str = readFile($fp); # Custom Function; Read entire file from file pointer and save in $str
$str = iconv("UTF-8", "WINDOWS-1252//TRANSLIT", $str); # Do the conversion
# Convert LF (Unix) to CRLF (Windows)
$str = preg_replace("/\n/", "\r\n", $str);
rewind($fp);
saveFile($fp, $str); # Custom Function; Save the file
return 1;
}
My code works fine except the encoding doesn't appear to be changing on the output file. When I open it in "KATE" (KDE) or Notepad++ (Windows), it still shows as UTF-8.
Instead of iconv, I have also tried:
$str = mb_convert_encoding($str, 'windows-1252', 'utf-8');
Thoughts? Grateful for the help, as this is driving me nuts!