1

I need to remove HTML tags from product description and short-description while exporting the products using the Magento default Import-Export module.

current CSV description column

<ul>
    <li>Foam-padded adjustable shoulder straps.</li>
    <li>900D polyester.</li>
    <li>Oversized zippers.</li>
    <li>Locker loop.</li>
</ul>

description column I want in CSV

Foam-padded adjustable shoulder straps.
900D polyester.
Oversized zippers.
Locker loop.

2 Answers 2

1

With Magento 2, to remove HTML tags :

In a Block or .phtml file

Just use $this->stripTags($html).

In a Controller

    /**
     * @var \Magento\Framework\Filter\FilterManager
     */
    protected $filterManager;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\Filter\FilterManager $filterManager
    ) {
        parent::__construct($context);
        $this->filterManager = $filterManager;
    }

    public function execute()
    {
        $html = "<ul>
                    <li>Foam-padded adjustable shoulder straps.</li>
                    <li>900D polyester.</li>
                    <li>Oversized zippers.</li>
                    <li>Locker loop.</li>
                </ul>";

        // Change thoses 2 variables if needed
        $allowableTags = null;
        $allowHtmlEntities = false;

        // Params are optionnal. If you use défault values you can remove it.
        $params = ['allowableTags' => $allowableTags, 'escape' => $allowHtmlEntities];

        $strWithoutHtml = $this->filterManager->stripTags($html, $params);

        die($strWithoutHtml); // Foam-padded adjustable shoulder straps. 900D polyester. Oversized zippers. Locker loop.
    }
1
  • 1
    The $this->stripTags($html) function is operating smoothly within the .phtml file. Thank you for your help! Mar 5 at 9:41
-1

This isn't related to magento but php.

Check strip_tags() function. She takes a string as a parameter and remove all tags from it.

$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
//Print Test paragraph. Other text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.