diff --git a/src/LukeSnowden/GoogleShoppingFeed/Item.php b/src/LukeSnowden/GoogleShoppingFeed/Item.php index d248c79..b79b380 100644 --- a/src/LukeSnowden/GoogleShoppingFeed/Item.php +++ b/src/LukeSnowden/GoogleShoppingFeed/Item.php @@ -143,13 +143,18 @@ public function sale_price($salePrice) /** * @param $description + * @param string $encoding */ - public function description($description) + public function description($description, string $encoding = '') { + if (empty($encoding)) { + $encoding = mb_internal_encoding(); + } + $description = preg_replace( "#]+>[^<]?#is", '', $description ); $node = new Node('description'); $description = $this->safeCharEncodeText($description); - $this->nodes['description'] = $node->value(substr($description, 0, 5000))->_namespace($this->namespace)->addCdata(); + $this->nodes['description'] = $node->value(mb_substr($description, 0, 5000, $encoding))->_namespace($this->namespace)->addCdata(); } /**