Skip to content

YehudaEi/php-parse-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

php-parse-csv

Parse CSV function in php

Use:

<?php
require('parseCSV.php');

$withTitles = true;
$data = parseCsv("myfile.csv", $withTitles);
print_r($data);

Result:

Array
(
    [0] => Array
        (
            [name] => John Doe
            [email] => [email protected]
            [phone] => +972501234567
            [course] => Array
                (
                    [0] => course 3
                    [1] => course 4
                )

        )

    [1] => Array
        (
            [name] => John Doe 2
            [email] => [email protected]
            [phone] => +972501234568
            [course] => Array
                (
                    [0] => course 2
                    [1] => course 6
                )

        )
)

Example

parse with titles:

$data = parseCsv("myfile.csv");
print_r($data);

Result:

Array
(
    [0] => Array
        (
            [name] => John Doe
            [email] => [email protected]
            [phone] => +972501234567
            [course] => Array
                (
                    [0] => course 3
                    [1] => course 4
                )

        )

    [1] => Array
        (
            [name] => John Doe 2
            [email] => [email protected]
            [phone] => +972501234568
            [course] => Array
                (
                    [0] => course 2
                    [1] => course 6
                )

        )
)

parse without titles:

$data = parseCsv("myfile.csv", false);
print_r($data);

Result:

Array
(
    [0] => Array
        (
            [0] => name
            [1] => email
            [2] => phone
            [3] => course

        )
     [1] => Array
        (
            [0] => John Doe
            [1] => [email protected]
            [2] => +972501234567
            [3] => course 3
            [4] => course 4

        )

    [2] => Array
        (
            [0] => John Doe 2
            [1] => [email protected]
            [2] => +972501234568
            [3] => course 2
            [4] => course 6

        )
)

Contact

[email protected]

License

MIT