mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Added function to detect delimiter using sep= file header
This commit is contained in:
committed by
Fonata
parent
bd2031582d
commit
fad5ebcdc8
@@ -1165,4 +1165,27 @@ class parseCSV {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect separator using a nonstandard hack: such file starts with the
|
||||||
|
* first line containing only "sep=;", where the last character is the
|
||||||
|
* separator.
|
||||||
|
*
|
||||||
|
* @access protected
|
||||||
|
*
|
||||||
|
* @param string $data file data
|
||||||
|
*
|
||||||
|
* @return string|false detected delimiter, or false if none found
|
||||||
|
*/
|
||||||
|
protected function _get_delimiter_from_sep($data) {
|
||||||
|
$sep = false;
|
||||||
|
// 32 bytes should be quite enough data for our sniffing, chosen arbitrarily
|
||||||
|
$sepPrefix = substr($data, 0, 32);
|
||||||
|
|
||||||
|
if (preg_match('/^sep=(.)/i', $sepPrefix, $sepMatch)) {
|
||||||
|
// we get separator.
|
||||||
|
$sep = $sepMatch[1];
|
||||||
|
}
|
||||||
|
return $sep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user