SplFileObject :: READ_CSV doesn't seem to read the CSV file correctly - ignoring the application "

I read the documentation and extensively researched this site before asking this question.

$file = new SplFileObject("/var/www/qacentre/compliance/compliance.csv");
$file->setFlags(SplFileObject::READ_CSV);
foreach ($file as $row) {

}

Example CSV string;

"ABEL, TAMMY 454454","End of: ABEL, TAMMY 454454",QP544454,28/10/2012 11:41,"0811 unlawfully use, possess","STEPHENS, JEREMY 54544454",LINK OPERATIONS,Located details incorrect,Entity: FORD FALCON Reg #: Colour: White

I repeated the output and it seems that it does not recognize the shell symbol ("). I tried to use it SetCSVControl, although I use the default application. I also tried to exit the shell symbol in SetCSVControl(since I do not control the CSV file that I export).

For example, when I print the result for the first column, which should be (ABEL, TAMMY 454454), I get ("ABEL).

I read that this could be a problem with setting my locale (en-GB, en-US; q = 0.8, en; q = 0.6)?

Any help would be great.

+5
source share
1

SplFileObject:: fgetcsv

 public array SplFileObject::fgetcsv ([ string $delimiter = "," [, string $enclosure = "\"" [, string $escape = "\\" ]]] )

:

<?php
$file = new SplFileObject("data.csv");
while (!$file->eof()) {
    var_dump($file->fgetcsv());
}
?>

<?php
$file = new SplFileObject("animals.csv");
$file->setFlags(SplFileObject::READ_CSV);
foreach ($file as $row) {
    list($animal, $class, $legs) = $row;
    printf("A %s is a %s with %d legs\n", $animal, $class, $legs);
}
?>

:

% s ,% d -

$file = new SplFileObject("/var/www/qacentre/compliance/compliance.csv");
$file->setFlags(SplFileObject::READ_CSV);
foreach ($file as $row) {
var_dump($row);
}

<?php

    $file = new SplFileObject("/var/www/qacentre/compliance/compliance.csv");
    while (!$file->eof()) {
        var_dump($file->fgetcsv());
    }
?>
+2

All Articles