这对大多数人来说可能很简单......
我在 Magento 中有这一行,它是发布到 Pinterest 的内容的一部分。
<?php echo urlencode( $_product->getShortDescription() ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>
在这的某个地方,我需要去除标签,因为简短描述使用所见即所得的编辑器,然后将标签添加到数据库中,我相信我需要在上面插入的是以下内容(因为 Magento 已经有这个功能):-
$this->stripTags
谁能告诉我如何在不破坏页面的情况下将其正确添加到上面?让我知道是否需要进一步提供任何东西。
提前致谢。
最佳答案
这使用了 php 的内置函数 strip_tags 并且应该可以工作:
<?php echo urlencode( strip_tags($_product->getShortDescription()) ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>
要使用 Magento 的功能,请使用:
<?php echo urlencode( $this->stripTags($_product->getShortDescription()) ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>
虽然这只有在 $this 指向“某物”的有效对象实例时才有效(抱歉,我不了解 Magento 的内部结构)
关于php - 在 Magento 中剥离 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9599399/