Remove BOM () from imported .csv file

后端 未结 6 1641
温柔的废话
温柔的废话 2020-11-27 20:40

I want to delete the BOM from my imported file, but it just doesn\'t seem to work.

I tried to preg_replace(\'/[\\x00-\\x1F\\x80-\\xFF]/\', \'\', $file);

6条回答
  •  渐次进展
    2020-11-27 20:49

    Read data with file_get_contents then use mb_convert_encoding to convert to UTF-8

    UPDATE

    $filepath = get_bloginfo('template_directory')."/testing.csv";
    $fileContent = file_get_contents($filepath);
    $fileContent = mb_convert_encoding($fileContent, "UTF-8");
    $lines = explode("\n", $fileContent);
    foreach($lines as $line) {
        $conls = explode(";", $line);
        // etc...
    }
    

提交回复
热议问题