mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Force enclosing of all columns with optional switch
This commit is contained in:
@@ -145,6 +145,15 @@ class parseCSV {
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $enclosure = '"';
|
public $enclosure = '"';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enclose All
|
||||||
|
* Force enclosing all columns
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $enclose_all = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conditions
|
* Conditions
|
||||||
@@ -1049,7 +1058,7 @@ class parseCSV {
|
|||||||
if ( $value !== null && $value != '' ) {
|
if ( $value !== null && $value != '' ) {
|
||||||
$delimiter = preg_quote($this->delimiter, '/');
|
$delimiter = preg_quote($this->delimiter, '/');
|
||||||
$enclosure = preg_quote($this->enclosure, '/');
|
$enclosure = preg_quote($this->enclosure, '/');
|
||||||
if ( preg_match("/".$delimiter."|".$enclosure."|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ') ) {
|
if ( preg_match("/".$delimiter."|".$enclosure."|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ') || $this->enclose_all ) {
|
||||||
$value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value);
|
$value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value);
|
||||||
$value = $this->enclosure.$value.$this->enclosure;
|
$value = $this->enclosure.$value.$this->enclosure;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user