diff --git a/src/Encoder/CsvEncoder.php b/src/Encoder/CsvEncoder.php index 5b5d396..deb069f 100644 --- a/src/Encoder/CsvEncoder.php +++ b/src/Encoder/CsvEncoder.php @@ -38,6 +38,20 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { protected $escapeChar; /** + * Whether to strip tags from values or not. Defaults to TRUE. + * + * @var bool + */ + protected $stripTags; + + /** + * Whether to trim values or not. Defaults to TRUE. + * + * @var bool + */ + protected $trimValues; + + /** * The format that this encoder supports. * * @var string @@ -55,11 +69,19 @@ class CsvEncoder implements EncoderInterface, DecoderInterface { * * @param string $escape_char * Indicates the character used for escaping. Defaults to "\" + * + * @param bool $strip_tags + * Whether to strip tags from values or not. Defaults to TRUE. + * + * @param bool $trim_values + * Whether to trim values or not. Defaults to TRUE. */ - public function __construct($delimiter = ",", $enclosure = '"', $escape_char = "\\") { + public function __construct($delimiter = ",", $enclosure = '"', $escape_char = "\\", $strip_tags = TRUE, $trim_values = TRUE) { $this->delimiter = $delimiter; $this->enclosure = $enclosure; $this->escapeChar = $escape_char; + $this->stripTags = $strip_tags; + $this->trimValues = $trim_values; if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); @@ -214,8 +236,10 @@ protected function flattenCell($data) { */ protected function formatValue($value) { // @todo Make these filters configurable. - $value = Html::decodeEntities($value); - $value = strip_tags($value); + if ($this->stripTags) { + $value = Html::decodeEntities($value); + $value = strip_tags($value); + } $value = trim($value); return $value; @@ -299,6 +323,8 @@ protected function setSettings(array $settings) { $this->delimiter = str_replace('\t', "\t", $settings['delimiter']); $this->enclosure = $settings['enclosure']; $this->escapeChar = $settings['escape_char']; + $this->stripTags = $settings['strip_tags']; + $this->trimValues = $settings['trim']; } }