使用OpenOffice制作csv文件并使用php转储csv数据

I have been following a csv import tutorial with PHP using mysql to store data, when I echo the data, I am getting the whole row instead of getting the data in the first cell. Could this be an issue with my csv file because my field delimited is: comma and my text delimited is: double quotes? when I echo out the first element echo $fileop[0];, I get the whole row instead of getting the first element which should be: title. Anyone would know what is the issue?

Here is my code:

<?php 

    $host = 'localhost';
    $user = 'root';
    $pass = 'root';
    $db_name = 'testcsvdump';

    $db = new mysqli($host, $user, $pass, $db_name);

    if($db->connect_errno > 0){
        die('Unable to connect to database [' . $db->connect_error . ']');
    }


    if( isset($_POST['submit']) ){

        $file = $_FILES['file']['tmp_name'];
        $handle = fopen($file, "r");

        while ( ($fileop = fgetcsv($handle, 1000, ',')) !== false ) {
            echo $fileop[0];
        }

    }else{
            echo 'failed';
        }


?>

and the output is:

titleNameEmail Address

(but I am trying to echo out "title" which is the first element in the first cell). And when I open my CSV file, each title and data are in their own cell. I used the following settings to export the file.

Field delimited is: comma

Text delimited is: double quotes

The issue was with the csv file itself, when I opened the csv with a text edito, I noticed that the end of each row did not have a comma so when I tried to echo the first element, the script was echoing out the first row. Once I added the missing commas in the csv file, the php script did exactly what it was supposed to do.

Great you solved your issue. I do have a suggestion that might make working with CSV files a little easier. I always tend to use this PHP library, it got things like auto detect and a lot of other usefull functions. It helped me a lot. Can't comment yet...

https://github.com/parsecsv/parsecsv-for-php