0

こんにちは私はこの問題を抱えています。

検証したい.csvがありますが、変数以外はnullになる可能性があります。

私の.csvが

A;ABC;
A;A;
A;A;
A;A;

そして、このファイルを読み取るphpは次のようになります。

$fd = fopen("uploads/".$nombreArchivo,"r");
        while (!feof($fd)){
                $lineTexto++;
                $reg = fgets($fd);
                $arreglo = explode(";", $reg);
                if(count($arreglo)==3){
                    if(!$arreglo[2]){
                        $_SESSION["info"]=$_SESSION["info"]."The cell 3 of the line $lineTexto can not be null<br/>";
                    }
                }
                else{
                    $_SESSION["info"]=$_SESSION["info"]."Número de líneas incorrectos en la linea $lineTexto<br/>";
                }
            }

結果は

4行目のセル3をnullにすることはできません

改行があるがnullである他のすべての行はどうですか?

御時間ありがとうございます。

4

1 に答える 1

1

それらはnullではありません..問題は、それらに空のスペースが含まれていることであり、これを使用してこれを解決できますtrim

    if (count($arreglo) == 3) {
        $arreglo[2] = trim($arreglo[2]);
        if (! $arreglo[2]) {
            echo "The cell 3 of the line $lineTexto can not be null<br/>";
        }
    } else {
        echo "Número de líneas incorrectos en la linea $lineTexto<br/>";
    }

出力例

The cell 3 of the line 1 can not be null
The cell 3 of the line 2 can not be null
The cell 3 of the line 3 can not be null
The cell 3 of the line 4 can not be null
于 2012-09-21T17:09:50.747 に答える