I have a CSV file that I need to change the encoding of. I want to be able to do this using PHP. I know there is the mb_convert_encoding function but that is only for strings.
Is there a function I can use to change the encoding of an entire csv file?
Cheers,
Updates: Turns out the solution to my problem would be to remove the BOM from my file.
I am using @treehouse code below and modified it to replace bom but it just fills the temp file forever whats wrong?
$sourcePath = 'EstablishmentExport.csv';
$tempPath = $sourcePath . 'temp';
$source = fopen($sourcePath, 'r');
$target = fopen($tempPath, 'w');
while(!feof($source)) {
$line = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $source);
fwrite($target, $line);
}
fclose($source);
fclose($target);
unlink($sourcePath);
rename($tempPath, $sourcePath);