Skip to content

Commit

Permalink
Merge pull request #45 from cloud-wu/fix/description
Browse files Browse the repository at this point in the history
fix - the description is wrong when the description length is over 5000 and it contains the multi-byte character
  • Loading branch information
lukesnowden authored Nov 9, 2020
2 parents 0bb708e + 60190df commit 037ece2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/LukeSnowden/GoogleShoppingFeed/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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( "#<iframe[^>]+>[^<]?</iframe>#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();
}

/**
Expand Down

0 comments on commit 037ece2

Please sign in to comment.