Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripping HTML tags in Magento

This is probably pretty simple for most...

I have this line in Magento which is part of what posts to Pinterest.

<?php echo urlencode( $_product->getShortDescription() ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>

Somewhere in this, I need to strip tags as the short description uses a WYSIWYG editor and subsequently adds tags to database, I believe what I need to insert to the above is the following (as Magento has this function already):-

$this->stripTags

Please could anyone advise how this can be correctly added to the above without it breaking the page? Let me know if I need to supply anything further.

Thanks in advance.

like image 483
zigojacko Avatar asked Dec 22 '22 01:12

zigojacko


1 Answers

This uses php's builtin function strip_tags and should work:

<?php echo urlencode( strip_tags($_product->getShortDescription()) ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>

To use Magento's function, use this:

<?php echo urlencode( $this->stripTags($_product->getShortDescription()) ) . " $" . urlencode( number_format( $_product->getPrice(),2 ) ); ?>

though this can only work if $this points to a valid object instance of "something" (sorry, I don't know Magento's internals)

like image 145
Hendrik Richter Avatar answered Dec 24 '22 03:12

Hendrik Richter