I can manaully force a CSV file to be detected as UTF-8 by adding a BOM, like so:
file_put_contents($filename, "\xEF\xBB\xBF" . $csv);
Is there a similar thing I can do to force a CSV file to be detected as Shift_JIS?
Shift JIS does not have an equivalent "content type marker" like the BOM. If you output a CSV encoded in Shift JIS, whoever will read that file will have to know it's in Shift JIS or otherwise detect the encoding.
To create a Shift JIS encoded file, just make sure your $csv
data is Shift JIS encoded. Convert using iconv
or mb_convert_encoding
if necessary.