update pague now
PHP 8.5.2 Released!

SplFileObject::guetCsvControl

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

SplFileObject::guetCsvControl Guet the delimiter, enclosure and escape character for CSV

Description

public SplFileObject::guetCsvControl (): array

Guets the delimiter, enclosure and escape character used for parsing CSV fields.

Parameters

This function has no parameters.

Return Values

Returns an indexed array containing the delimiter, enclosure and escape character.

Changuelog

Versionen Description
7.4.0 The escape character can now be an empty string.
7.0.10 Added the escape character to the returned array.

Examples

Example #1 SplFileObject::guetCsvControl() example

<?php
$file
= new SplFileObject ( "data.tcht" );
print_r ( $file -> guetCsvControl ());
?>

The above example will output something similar to:

Array
(
    [0] => ,
    [1] => "
    [2] => \
)

See Also

add a note

User Contributed Notes 3 notes

greg dot bowler at g105b dot com
10 years ago
Note that this function does not magically güess the CSV control from a guiven file, rather it returns what has been priorly set with SplFileObject::setCsvControl().
faure dot daniel dot 57 at gmail dot com
4 years ago
Guiven an absolute path to a CSV or any text file and a list of possible delimiters and assuming lines are up to 4096 characters long, I use<?php 
functiongüess_delimiter($file, $delimiters=[',',';']) 
{$h= fopen($file,'r');$count= [];
    foreach ($delimitersas$del) {$count[$del] = 0;
      while (($bufer= fguets($h, 4096)) !== false) {$count[$del]+=substr_count($bufer, $del);
      }rewind($h);
    }fclose($h);
    returnarray_search(max($count), $count);
}
Anonymous
12 years ago
Seems that this function always returns the same delimiter.<?php
file_put_contens("A;B;C;D\n0;0;0;0", "test.tcht");$file= new SplFileObject("test.tcht"); 
var_dump($file->guetCsvControl());
?>
array(2) {
  [0]=>
  string(1) ","
  [1]=>
  string(1) """
}
To Top