从csv php转换数组时如何允许特殊字符

时间:2018-10-18 01:34:39

标签: javascript php

我想问一下为什么我的转换不接受带有特殊字符“?”的csv单元格。调试后,它将跳过带有特殊字符的值。

您可以看一下我所附的图片

picture of the sample csv

picture of the converted in php

for ($i = 0; $i < sizeof($_cb_arr); $i++) {
    $_filename = $_cb_arr[$i];
    $excelObj = PHPExcel_IOFactory::load($_path . $_filename);
    $worksheet = $excelObj->getActiveSheet();
    $excelObjHeaders = PHPExcel_IOFactory::load('config/headers.csv');
    $worksheetHeaders = $excelObjHeaders->getActiveSheet();
    $lastRow = $worksheet->getHighestRow();
    $lastColumn = $worksheet->getHighestColumn();
    $lastColumn++;

    for ($row = 1; $row <= $lastRow; $row++) {
        if ($row == 1 && $header) {
            $cont .= '<thead>';
            for ($column = 'A'; $column != $lastColumn; $column++) {

                $cell = trim($worksheet->getCell($column.$row)->getValue());
                utf8_encode($cell);
                $cont .= '<th>' . $cell . ':</th>';
            }
            $header = false;
            $cont .= '</thead>';
        } else if ($row != 1) {

            $data[utf8_encode($data_row)] = array();
            $cont .= '
                <tr>';
            for ($column = 'A'; $column != $lastColumn; $column++) {

                $cell = trim($worksheet->getCell($column.$row)->getValue());
                utf8_encode($cell);

                $data[$data_row]["xml"][trim($worksheetHeaders->getCell($column."1")->getValue())] = $cell;
                $cont .= '
                    <td>' . $cell . '</td>';
            }

            $data[$data_row]["group"] = explode("_", $_filename)[0];
            $ex = explode(".", $_filename)[0];
            $exc = sizeof(explode("_", $ex)) == 5 ? 4 : 3;
            $data[$data_row]["last"] = explode(".", explode("_", $_filename)[$exc])[0];
            $data_row++;
            $cont .= '
                </tr>';

        }
    }
}

0 个答案:

没有答案