-2

我正在使用 PHP 读取 CSV 文件,我获取了每一行的所有值,但是某些具有长数据的列显示类似这样9.21008E+15 的内容我不知道如何获取假设是这样的完整值9210080000000000

if (($handle = fopen("Test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
    $num = count($data);
    $tb_row = "";
    for ($c=0; $c < $num; $c++) {
        $tb_row .= $data[$c].",";
    }
    $new_row = substr($tb_row, 0, -1);//removing the comma at the end of line...
    //explode and assign values then insert
    $each_col = explode(',', $new_row);
    $Device_state = $each_col[0];
    $udid = $each_col[8];
    $imsi = $each_col[9];
    $imei = $each_col[10];
    echo "$imsi || $imei"."<br />";
}
}
4

2 回答 2

0

向有此问题的单元格添加前缀解决了问题 (')

于 2017-06-23T08:58:37.593 回答
0

您只需将其转换回整数值

if (($handle = fopen("Test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
        $num = count($data);
        $tb_row = "";
        for ($c=0; $c < $num; $c++) {
            if (strpos($data[$c], 'E+'))
                $data[$c] = intval((float)$data[$c]);

            $tb_row .= $data[$c].",";
        }
        $new_row = substr($tb_row, 0, -1);//removing the comma at the end of line...
        //explode and assign values then insert
        $each_col = explode(',', $new_row);
        $Device_state = $each_col[0];
        $udid = $each_col[8];
        $imsi = $each_col[9];
        $imei = $each_col[10];
        echo "$imsi || $imei"."<br />";
    }
}
于 2017-06-23T09:04:28.140 回答