Excel csv export into a php file with fgetcsv

前端 未结 5 1608
粉色の甜心
粉色の甜心 2021-01-13 17:32

I\'m using excel 2010 professional plus to create an excel file. Later on I\'m trying to export it as a UTF-8 .csv file. I do this by saving it as CSV (symbol separated....

5条回答
  •  执笔经年
    2021-01-13 18:33

    From PHP DOC

    Locale setting is taken into account by this function. If LANG is e.g. en_US.UTF-8, files in one-byte encoding are read wrong by this function.

    You can try

    header('Content-Type: text/html; charset=UTF-8');
    $fp = fopen("log.txt", "r");
    echo "
    ";
    while ( ($dataRow = fgetcsv($fp, 1000, ";")) !== FALSE ) {
        $dataRow = array_map("utf8_encode", $dataRow);
        print_r($dataRow);
    }
    

    Output

    Array
    (
        [0] => ID
        [1] => englishName
        [2] => germanName
    )
    Array
    (
        [0] => 1
        [1] => Austria
        [2] => Österreich
    )
    

提交回复
热议问题