You are here:  » Strip HTML

Support Forum



Strip HTML

Submitted by Halion on Sun, 2012-10-14 11:48 in

Hi David,

I want to strip out stuff like ® and ‘ etc from the description column. Could you confirm that STRIP HTML does this, or must I set up a filter for each that I want removed?

Thanks

Mike

Submitted by support on Sun, 2012-10-14 12:10

Hello Mike,

Strip HTML won't remove HTML entities such as ® as they are not strictly HTML markup, which is what is removed by the strip_tags() function that is used by the Strip HTML filter.

In this post you will find code for a new filter, Search and Replace RegExp which could be used to strip entities. After adding the filter code to your includes/filter.php file, the Search expression required would be:

/&(.*);/u

...and leave the Replace box empty - and that should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by Halion on Fri, 2012-10-19 13:57

Thanks for your reply, I've been trying your suggestion but it won't work.

I'm trying to remove stuff like & # 1 7 4 ; (I've put spaces in between each letter so it displays ok here, the original feed doesn't have those spaces), from the product description column as it obviously doesn't look too nice if that sort of code is sprinkled around the description.
I'm wondering if the # is the problem?

Submitted by support on Fri, 2012-10-19 14:03

Hi,

# should be matched by (.*) but I just noticed I included the wrong flag for ungreedy matching - it should be upper-case rather than lower-case u - could you try:

/&(.*);/U

Cheers,
David.
--
PriceTapestry.com

Submitted by Halion on Fri, 2012-10-19 14:09

Hi again David,

As I couldn't get it to work I've knocked up some php which does what I want in searchresults.php

<?php
  $d1 
= (tapestry_substr($product["description"],250,"..."));  $d2 ereg_replace("[^A-Za-z0-9.,'-:]"" "$d1); $d3 = array("8482;""174;""8216;""8217;""8230;""amp;""8482""174""8216""8217""8230""amp"";");
$d4 str_replace($d3"""$d2"); 
?>

<?php
 
print $d4
?>

It does the job and the string can be amended as required. hopefully it shouldn't increase server load too much as it does it on the page load :)

Submitted by support on Fri, 2012-10-19 14:11

That's great - i'll check the regexp out on my test server for completeness anyway - shouldn't be any performance problem with your sol..

Cheers,
David.
--
PriceTapestry.com