Unable to detect delimiter in CSV file when CSV file is UTF format

145 views Asked by At

I have a CSV file like below

マテル・インターナショナル株式会社,dog
株式会社タカラトミーアーツ,apple
大網株式会社,banana

I have used SplFileObject to get CSV ,

$file = new SplFileObject(my_path);
$file->setFlags(SplFileObject::READ_CSV  | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);

foreach ($file as $key => $row) {
    print_r($row);
}

I have gotten below output in console, My script will run in shell not in browser.

Array
(
    [0] => マテル・インターナショナル株式会社
    [1] => dog
)

Array
(
    [0] => 株式会社タカラトミーアーツ,apple
)

Array
(
    [0] => 大網株式会社
    [1] => banana
)

I am trying in console not in browser.

Here for 1st line Array is okay but for 2nd line data showing in array single element. All of lines contain a comma.How I can solve this issue for encoding character ?

0

There are 0 answers