I have been making a program that creates multiple CSV's from another source CSV (encoded in 'SJIS'/SHIFT-JIS). Here's the process in which I am creating them:
- Create a string, which will hold the contents of the output CSV's
- Fill in said strings with their proper information
- Encode the string to UTF-8 from SJIS using mb_convert_encoding()
code:
$contents2 = mb_convert_encoding($contents, "UTF-8", "SJIS"); Create a zip archive using PHP's provided library methods and append the files I desire with their corresponding strings using addFromString() code:
$zipFileName = "output.zip";$zip = new ZipArchive; if ($zip->open($zipFileName, ZipArchive::CREATE) === TRUE){ $zip->addFromString('customer.csv', $contents2); ...do for the other files $zip->close(); } else{ echo 'Failed! File not created!'; }
- Prompt the user with a dialogue box to save the file in their desired location. code: $zipContents = file_get_contents($zipFileName); header('Content-Type: application/zip'); header("Content-Disposition: attachment; filename=inflow.zip"); header("Pragma: no-cache"); header("Expires: 0"); echo $zipContents;
Now here is my problem: The files that I have created from the zip file are encoded in "UTF-8 without BOM" when I open it in Notepad++. However, I require for these files to just be in plain "UTF-8". A inventory program I am using to upload these files, for reasons beyond me, will not show the proper characters for the CSV's encoded in "UTF-8 without BOM". Once I manually: open the files, re-encode it as "UTF-8", and save them, are the files able to display the correct characters in this inventory program.
I have read a good deal of articles talking about the converse of this problem, where people were seeking to make their UTF-8 files become encoded without BOM. However, my situation is the exact opposite of this. If there's an easy solution in PHP I would more than welcome the help! Thanks for reading!!